|NO.Z.00034|——————————|LinuxShell|——|Linux&Shell$基础.V03|——|脚本执行方式|

一、shell脚本执行方式
### --- 编写一个shell脚本

!/bin/Bash 
~~~     # 注:
~~~     这个不是注释,是bash bang,可以理解为标识的是以下程序写的是shell程序,
~~~     告诉系统应该需要使用什么程序来解释这个语言。这句话对于shell脚本是不可以执行的。
~~~     若是写入的是纯shell脚本且是在linux环境下,不写!/bin/bash是可以执行的
~~~     若是在shell中嵌套更高级的语言:比如在人际交互的模式下,
~~~     需要使用其它语言,若是你不写!/bin/bash这个程序是不会去执行的
echo "Mr. yanqi is the most honest man! "
~~~     # 注:
~~~     若是在后面加入!需要加空格,若是不加,系统会报错
[root@localhost ~]# vim hello.sh
#!/bin/bash
echo "Mr. yanqi is the most honest man!  "
 
[root@localhost ~]# echo  "Mr. yanqi is the most honest man!"
-bash: !": event not found
[root@localhost ~]# echo  "Mr. yanqi is the most honest man! "
Mr. yanqi is the most honest man!  
二、shell执行一:
### --- shell执行一: 
~~~     Shell 脚本写好了,那么这个脚本该如何运行呢?
~~~     在 Linux 中脚本的执行主要有这样两种种方法:

~~~     # 赋予执行权限,直接运行
~~~     这种方法是最常用的 Shell 脚本运行方法,也最为直接简单。
~~~     就是赋予执行权限之后,直接运行。
~~~     当然运行时可以使用绝对路径,也可以使用相对路径运行。命令如下:

~~~     #注:
~~~     因为我们已经在/root/目录当中,所以也可以使用相对路径运行
### --- 赋予执行权限
[root@localhost ~]# chmod 755 hello.sh 
 
### --- 使用绝对路径运行
[root@localhost ~]# /root/hello.sh 
Mr. yanqi is the most honest man! 
[root@localhost ~]# ./hello.sh 
Mr. yanqi is the most honest man!  
三、shell执行二:
### --- shell执行二:
~~~     通过 Bash 调用执行脚本;直接使用bash直接调用,不需要执行权限;
~~~     这种方式并不提倡使用

[root@localhost ~]# bash hello.sh 
Mr. yanqi is the most honest man! 

 
 
 
 
 
 
 
 
 

Walter Savage Landor:strove with none,for none was worth my strife.Nature I loved and, next to Nature, Art:I warm'd both hands before the fire of life.It sinks, and I am ready to depart
                                                                                                                                                   ——W.S.Landor

 

 

posted on   yanqi_vip  阅读(17)  评论(0编辑  收藏  举报

相关博文:
阅读排行:
· 无需6万激活码!GitHub神秘组织3小时极速复刻Manus,手把手教你使用OpenManus搭建本
· Manus爆火,是硬核还是营销?
· 终于写完轮子一部分:tcp代理 了,记录一下
· 别再用vector<bool>了!Google高级工程师:这可能是STL最大的设计失误
· 单元测试从入门到精通
< 2025年3月 >
23 24 25 26 27 28 1
2 3 4 5 6 7 8
9 10 11 12 13 14 15
16 17 18 19 20 21 22
23 24 25 26 27 28 29
30 31 1 2 3 4 5

导航

统计

点击右上角即可分享
微信分享提示