Shell脚本执行的四种方法
(1).bash(或sh) [脚本的相对路径或绝对路径]
[xf@xuexi ~]$ cat a.sh
#!/bin/bash
echo "hello world!"
[xf@xuexi ~]$ bash a.sh
hello world!
[xf@xuexi ~]$ which bash
/usr/bin/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
可以看到sh命令实际指向的是bash命令,sh只是bash的一个软链接
(2).source(或.) [脚本的相对路径或绝对路径]
.(点)是等同于source的,最常见的使用是在重新加载环境变量时。
[xf@xuexi ~]# source a.sh
hello world!
[xf@xuexi ~]# . a.sh
hello world!
(3).sh < [脚本名称]或者cat [脚本名称] | sh(或bash)
[xf@xuexi ~]# sh < a.sh
hello world!
[xf@xuexi ~]# cat a.sh | sh
hello world!
(4).脚本的相对路径或绝对路径,使用该方法,脚本必须拥有执行权限
[xf@xuexi ~]$ chmod +x a.sh
[xf@xuexi ~]$ ./a.sh
hello world!
[xf@xuexi ~]$ /home/xf/a.sh
hello world!
Shell脚本执行的四种方法的更多相关文章
- Linux中执行shell脚本命令的4种方法总结
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本所在 ...
- 【Shell脚本】运行shell脚本文件的几种方法与区别
Shell脚本不同的运行方式会对当前Shell设置或者运行结果有所不同. 假设现在有一个脚本名为display_shell_script_args.sh,其内容如下: #!/home/pyf/bin/ ...
- SHELL脚本运行的几种方法以及区别
#1 给脚本加上执行权限chmod u+x a.sh, 而后就可以直接用全路径来执行脚本了,比如当前文件夹下用./a.sh,如果如果脚本所在目录在PATH环境变量之中, 则直接用a.sh即可(这和运行 ...
- shell脚本执行的三种方式
(1) bash script_name 或 sh script_name 推荐使用此方法,script_name 不需要执行权限亦可执行. (2) path/script_name 或 ...
- iOS延时执行的四种方法
@import url(http://i.cnblogs.com/Load.ashx?type=style&file=SyntaxHighlighter.css);@import url(/c ...
- shell脚本去重的几种方法
测试文件 [root@bogon ~]# cat >test jason jason jason fffffjason 按 Ctr + D保存 1.sort -u [root@bogon ~]# ...
- 2.8 补充:shell脚本执行方法
bash shell 脚本的方法有多种,现在作个小结.假设我们编写好的shell脚本的文件名为hello.sh,文件位置在/data/shell目录中并已有执行权限. 方法一:切换到shell脚本 ...
- Shell脚本中引用、调用另一个脚本文件的2种方法
Shell脚本中引用.调用另一个脚本文件的2种方法 http://www.jb51.net/article/67903.htm
- linux安装IPython四种方法
IPython是Python的交互式Shell,提供了代码自动补完,自动缩进,高亮显示,执行Shell命令等非常有用的特性.特别是它的代码补完功能,例如:在输入zlib.之后按下Tab键,IPytho ...
随机推荐
- 1.Hbase简介
1. Hbase简介 1.1. 什么是hbase(面向列) HBASE是一个高可靠性.高性能.面向列.可伸缩的分布式存储系统,利用HBASE技术可在廉价PC Server上搭建起大规模 结构化存储集群 ...
- Python一些细节
1.python set() dict() 有序问题,不同版本之间的差异,与Java/C++的对比 https://www.cnblogs.com/niuxichuan/p/11608386.html ...
- 部署WCF Lib到IIS
打开VS2013,新建项目,选择WCF|WCF服务库,取名WCFWithIIS 2. 我们用演示一个计算加法的服务.简单起见,直接在IService接口中添加加法接口 3. 实现这个加法 4. 生成项 ...
- 下载uhd_images_downloader出现报错
下载uhd_images_downloader出现报错 [INFO] Images destination: /usr/local/share/uhd/images [INFO] No invento ...
- 《流畅的Python》Object References, Mutability, and Recycling--第8章
Object References, Mutability, and Recycling 本章章节: Variables Are Not Boxes identity , Equality , Al ...
- Vuex的mapGetters方法使用报错
报错信息: ERROR in ./node_modules/babel-loader/lib!./node_modules/vue-loader/lib/selector.js?type=script ...
- 2019牛客多校第三场D BigInteger——基础数论
题意: 用 $A(n)$ 表示第 $n$ 个只由1组成分整数,现给定一个素数 $p$,求满足 $1 \leq i\leq n, 1 \leq j \leq m, A(i^j) \equiv 0(mo ...
- 3、python--第三天练习题
#1.简述普通参数.指定参数.默认参数.动态参数的区别 #1.普通参数就是传入的函数,没有默认值 def f(a): a = a + 1 return a print(f(3)) #2.指定参数 de ...
- jvm参考(生产使用)
#4g JAVA_OPTS=-Xms3g -Xmx3g -XX:+PrintFlagsFinal -XX:+UnlockDiagnosticVMOptions -XX:NewRatio=2 -XX:P ...
- electron 打包成桌面运用
最近在学习nodejs,得知Electron是通过将Chromium和Node.js合并到同一个运行时环境中,用HTML,CSS和JavaScript来构建跨平台桌面应用程序的一门技术.对于之前一直从 ...