[记录备忘][研究学习]
通过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
原书截图
网友评论