1. 脚本无执行权限时,用 ./xx.sh 会报错: root@nagios-client02 git-wzz]# ./check_rsync.sh -bash: ./check_rsync.sh: Permission denied 用sh xx.sh 会执行 2. 脚本有执行权限 sh xx.sh 和 ./xx.sh 都会以子进程执行。 该子进程shell会继承父shell的环境变量,但子shell新建、修改的变量不会带回父进程 3. . xx.sh或source xx.sh 时 会读取脚本内容并在当前shell中执行、并没有新建子shell。 脚本里新建,修改的变量都会保存在当前shell里 4. 例如:[oldboy@test ~]$ cat test.sh
user=`whoami`
[oldboy@test ~]$sh test.sh
[oldboy@test ~]$echo $user
空
[oldboy@test ~]$ [root@test ~]# . test.sh [root@test ~]# echo $user root 参考:http://www.51testing.com/html/38/225738-206878.html点击打开链接