版权声明:silly8543 https://blog.csdn.net/cen50958/article/details/89914742
1.shell脚本执行
- bash script-name 或 sh script-name
脚本文件本事没有可执行权限(x)或者文件开头没有指定解释器sh test.sh bash test.sh
- path/script-name 或./script-name
需要先将脚本文件的权限修改为可执行(chmod u+x script-name 或 chmod 755 script-name)权限/server/scripts/test.sh ./test.sh
- source script-name 或 . script-name
source 和.执行脚本可以将执行的脚本的函数和变量带到当前执行的shell中
第三种执行方法和前两种的区别:source test.sh . test.sh
2.shell脚本后台运行
-
nohup
nohup sh test.sh > out.txt &
out.txt为输出日志的地方
-
sh
sh test.sh >& out.txt &