shell脚本加不加export的区别
加了export:
jackyyu@ubuntu:~$ cat 1.sh
#!/bin/dash
test=test
echo ${test}
echo ${TERM}
TERM=dumb
export test=test2
./2.sh
jackyyu@ubuntu:~$ cat 2.sh
#!/bin/bash
echo ${TERM}
echo ${test}
jackyyu@ubuntu:~$ sudo ./1.sh
test
vt100
dumb
test2
去掉export:
jackyyu@ubuntu:~$ cat 1.sh
#!/bin/dash
test=test
echo ${test}
echo ${TERM}
TERM=dumb
test=test2
./2.sh
jackyyu@ubuntu:~$ cat 2.sh
#!/bin/bash
echo ${TERM}
echo ${test}
jackyyu@ubuntu:~$ sudo ./1.sh
test
vt100
dumb
jackyyu@ubuntu:~$
结论:
1. 对于环境变量,对于调用子脚本加不加效果一样
2. 非环境变量,不加export 在子脚本中取不到数据