子Shell脚本实现方式1-来自《跟老男孩学Linux运维:Sh

2022-02-21  本文已影响0人  墨韵

[记录备忘][研究学习]
通过Shell脚本来实现一个由“&”产生的子Shell

parent_var="Parent"
echo "Shell Start:ParentShell Level: $BASH_SUBSHELL"
{
    echo "SubShell Level: $BASH_SUBSHELL"
    sub_var="Sub"
    echo "sub_var=$sub_var"
    echo "parent_var=$parent_var"
    sleep 2
    echo "SubShell is over."
} &
echo "Now ParentShell start again."
echo "Shell Over:ParentShell Level: $BASH_SUBSHELL"
if [ -z "$sub_var" ]; then
    echo "sub_varisnotdefinedinParentShell"
else
    echo "sub_varisdefinedinParentShell "
fi
原书截图
上一篇下一篇

猜你喜欢

热点阅读