demo:参考shell十三问的例子
新建2个脚本
1.sh
#!/bin/bash
A=B
echo "PID for 1.sh before exec/source/fork:$$"
export A
echo "1.sh:\$A is $A"
case $1 in
exec)
echo "using exec..."
exec ./2.sh;;
source)
echo "using source..."
. ./2.sh;;
echo "using fork by default..."
./2.sh;;
esac
echo "PID for 1.sh after exec/source/fork:$$"
echo "1.sh:\$A is $A"
2.sh
#~/bin/bash
echo "PID for 2.sh:$$"
echo "2.sh get \$A=$A from 1.sh"
A=C
export A
echo "2.sh:\$A is $A"
运行./1.sh即可看到区别
点赞
x
海报分享
扫一扫,分享海报