Linux中执行shell脚本的4种方法
来源:互联网 发布:时间管理 知乎 编辑:程序博客网 时间:2024/06/05 16:08
Linux中执行shell脚本的4种方法
1,切换到shell脚本所在目录,执行shell脚本;
cd /home/patch
./start.sh
2,以绝对路径的方式执行bash shell脚本;
/home/patch/start.sh
3,直接使用bash 或者 sh执行shell脚本;
cd /home/patch
bash start.sh
或者
cd /home/patch
sh start.sh
这种方式执行shell脚本,可以不必设定shell的执行权限,甚至都不用在shell文件
中指定bash的路径。因为这种方式是将start.sh作为参数传递给bash或者sh来执行的。这
时不是start.sh自己来执行,而是被bash或者sh调用执行。
4,在当前的shell环境中执行bash shell脚本;
cd /home/patch
. start.sh
或者
cd /home/patch
source start.sh
总结:前三种方式,执行shell脚本,都是在当前shell(称为父shell)开启一个子shell
环境,此shell脚本就在这个子shell环境中执行。shell脚本执行完后子shell环境随即关
闭,然后又回到父shell中。而方法4是在当前shell中执行的。
1,切换到shell脚本所在目录,执行shell脚本;
cd /home/patch
./start.sh
2,以绝对路径的方式执行bash shell脚本;
/home/patch/start.sh
3,直接使用bash 或者 sh执行shell脚本;
cd /home/patch
bash start.sh
或者
cd /home/patch
sh start.sh
这种方式执行shell脚本,可以不必设定shell的执行权限,甚至都不用在shell文件
中指定bash的路径。因为这种方式是将start.sh作为参数传递给bash或者sh来执行的。这
时不是start.sh自己来执行,而是被bash或者sh调用执行。
4,在当前的shell环境中执行bash shell脚本;
cd /home/patch
. start.sh
或者
cd /home/patch
source start.sh
总结:前三种方式,执行shell脚本,都是在当前shell(称为父shell)开启一个子shell
环境,此shell脚本就在这个子shell环境中执行。shell脚本执行完后子shell环境随即关
闭,然后又回到父shell中。而方法4是在当前shell中执行的。
0 0
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- Linux中执行shell脚本的4种方法总结
- leecode 解题总结:263. Ugly Number
- tonesoft
- 并查集主要知识
- javascript-ife笔记-javascript和树
- 傻傻分不清楚super与this
- Linux中执行shell脚本的4种方法
- SpringAOP拦截Controller,Service实现日志管理(自定义注解的方式)
- 值得推荐的android开源框架
- 图论算法----并查集中的启发式合并
- Spring MVC中AOP无效、不起作用,解决方案之一
- 使用Spring进行切面(AOP)编程
- 10分钟精通SharePoint-搜索
- 杭电 hdu 2073. 无限的路
- SQL高级语句-SQL 通配符-在搜索数据库中的数据时,SQL 通配符可以替代一个或多个字符。