如何执行Shell脚本

2018-12-05  本文已影响10人  南风nanfeng

通常执行shell脚本有两种方式。以脚本/data/shell/test.sh为例:

#!/bin/bash
echo "Please Enter Your Name: "
read yourName
echo "this is your name : "$yourName

这两种方式要求脚本具有可执行权限,如果不没有执行权限则给出提示:

[root@sell131 shell]# ./test.sh
-bash: ./test.sh: Permission denied

// 需要先给脚本赋予可执行权限
[root@sell131 shell]# chmod u+x test.sh

实际上还有另外三种执行脚本的方式。

[root@sell131 shell]# . ./test.sh 
Please Enter Your Name: 
test
this is your name : test
[root@sell131 shell]# source test.sh 
Please Enter Your Name: 
test
this is your name : test
[root@sell131 logs]# /bin/bash test.sh 
Please Enter Your Name: 
test
this is your name : test

整理自: http://c.biancheng.net/view/739.html

上一篇 下一篇

猜你喜欢

热点阅读