zoukankan      html  css  js  c++  java
  • source exec 区别(shell 13问中摘出)

    exec也是让script在同一个进程上执行,但是原有进程则被结束了

    脚本内容:

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# cat 1.sh
    #!/bin/sh
    A=B
    echo "PID for 1.sh :$$"
    export A
    echo "1.sh \$A is $A"
    case $1 in
            exec)
                    echo "using exec..."
                    exec ./2.sh;;
            source)
                    echo "using source..."
                    source ./2.sh;;
            *)
                    echo "using fork..."
                    ./2.sh;;
    esac

    echo "PID for 1.sh after run 2.sh: $$"
    echo "1.sh \$A is $A"

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# cat 2.sh
    #!/bin/sh
    echo "PID for 2.sh :$$"

    echo "2.sh get \$A=$A from 1.sh"
    A=C
    export A
    echo "2.sh \$A is $A"

    运行结果:

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh
    PID for 1.sh :8152
    1.sh $A is B
    using fork...
    PID for 2.sh :8153
    2.sh get $A=B from 1.sh
    2.sh $A is C
    PID for 1.sh after run 2.sh: 8152
    1.sh $A is B

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh source
    PID for 1.sh :8158
    1.sh $A is B
    using source...
    PID for 2.sh :8158
    2.sh get $A=B from 1.sh
    2.sh $A is C
    PID for 1.sh after run 2.sh: 8158
    1.sh $A is C

    root@james-desktop:/opt/qt-everywhere/marvell/APP/applications/factory-roast# ./1.sh exec
    PID for 1.sh :8159
    1.sh $A is B
    using exec...
    PID for 2.sh :8159
    2.sh get $A=B from 1.sh
    2.sh $A is C

  • 相关阅读:
    Kafka日志段源码分析
    Kafka日志结构概览
    LDAP统一身份认证解读及实践
    Keycloak集成三方身份提供者的注销流程
    Keycloak会话管理-refreshToken
    Cas校验INVALID_TICKET-not recognized
    如何获取Docker容器的root权限
    OIDC-code to token
    Newrelic集成wildfly报NoClassDefFoundError
    Cookie深入详解
  • 原文地址:https://www.cnblogs.com/cute/p/2095911.html
Copyright © 2011-2022 走看看