在学习鸟哥的Linux教程的shell scripts这一章,按照例程输入如下脚本:
1 #!/bin/bash
2 # Program:
3 # This program is used to show "Hello World !" in screen.
4 # History:
5 # 2016/6/14 Mickey First release
6 PATH=/bin:/sbin:/usr/bin:/usr/sbin:/usr/local/bin:/usr/local/sbin:~/bin
7 export PATH
8 echo -e "Hello World ! \a \n"
9 exit 0
命名为sh01.sh,分别用sh和./来运行,结果如下:
root@obama-ubuntu:/tmp/scripts# sh sh01.sh
-e Hello World !
root@obama-ubuntu:/tmp/scripts# ./sh01.sh
Hello World !
在网上查了一下,对于我现在用的ubuntu 15来说,用“sh”执行是调用“/bin/sh”作为执行器,而采用“./”执行是调用申明的“/bin/bash”,而“sh”可能不支持“echo -e”,所以把“-e”作为内容输出。“./”是更好的执行方式,或者也可采用“bash”方式运行:
root@obama-ubuntu:/tmp/scripts# bash sh01.sh
Hello World !