首页 > 系统服务 > 详细

Shell脚本执行的五种方法

时间:2019-05-03 16:43:21      阅读:109      评论:0      收藏:0      [点我收藏+]

(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!

  

Shell脚本执行的五种方法

原文:https://www.cnblogs.com/diantong/p/10805460.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!