• 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

  • 相关阅读:
    PHP 连接oracle
    PHP 简易导出excel 类解决Excel 打开乱码
    Linux下Apache网站目录读写权限的设置
    PHP behavior 机制简单实现
    RewriteCond和13个mod_rewrite应用举例Apache伪静态
    PHP event 事件机制
    PHP 函数引用传值
    django数据库连接快速配置
    解决Django项目数据库无法迁移问题
    生成uuid唯一标识符
  • 原文地址:https://www.cnblogs.com/cute/p/2095911.html
Copyright © 2020-2023  润新知