(1).bash [脚本名称]
[xf@xuexi ~]$ cat a.sh #!/bin/bash echo "hello world!" [xf@xuexi ~]$ bash a.sh hello world! [xf@xuexi ~]$ which bash /usr/bin/bash
(2).sh [脚本名称]
实际上sh指向的也是bash
[xf@xuexi ~]$ sh a.sh hello world! [xf@xuexi ~]$ which sh /usr/bin/sh [xf@xuexi ~]$ ll /usr/bin/sh lrwxrwxrwx. 1 root root 4 4月 5 22:07 /usr/bin/sh -> bash
(3).使用./[脚本名称],但脚本文件必须有执行权限
[xf@xuexi ~]$ chmod +x a.sh [xf@xuexi ~]$ ./a.sh hello world!
(4).使用绝对路径,脚本文件一样需要执行权限
[xf@xuexi ~]$ /home/xf/a.sh hello world! [xf@xuexi ~]$ ll a.sh -rwxrwxr-x. 1 xf xf 32 5月 3 16:01 a.sh
(5).sh < [脚本名称]或者cat [脚本名称] | sh(bash)
[xf@xuexi ~]$ sh<a.sh hello world!
原文:https://www.cnblogs.com/diantong/p/10805460.html