linux多线程执行shell脚本,linux执行shell脚本的四种方式

linux执行shell脚本的四种方式

发布时间:2020-04-11 10:54:55

来源:亿速云

阅读:145

作者:小新

这篇文章主要为大家详细介绍了linux执行shell脚本的四种方式,文中示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下。

45c04afeb8bd68c33a97cfd46e0df048.png

Linux中shell脚本的执行通常有4种方式,分别为工作目录执行,绝对路径执行,sh执行,shell环境执行。

首先,看下我们的脚本内容[tan@tan scripts]$ ll

total 4

-rw-rw-r--. 1 tan tan 68 May 8 23:18 test.sh

[tan@tan scripts]$ cat test.sh

#!/usr/bin/bash

/usr/bin/python <

print "Hello Shell"

EOF

1、工作目录执行

工作目录执行,指的是执行脚本时,先进入到脚本所在的目录(此时,称为工作目录),然后使用 ./脚本方式执行[tan@tan scripts]$ ./test.sh

-bash: ./test.sh: Permission denied

[tan@tan scripts]$ chmod 764 test.sh

[tan@tan scripts]$ ./test.sh

Hello Shell

报了权限错误,这里需要赋权,使用chmod 764 test.sh 赋权后就可以正常执行了。

2、绝对路径执行

绝对路径中执行,指的是直接从根目录/到脚本目录的绝对路径[tan@tan scripts]$ pwd

/home/tan/scripts

[tan@tan scripts]$ `pwd`/test.sh

Hello Shell

[tan@tan scripts]$ /home/tan/scripts/test.sh

Hello Shell

3、sh执行

sh执行,指的是用脚本对应的sh或bash来接着脚本执行[tan@tan scripts]$ sh test.sh

Hello Shell

[tan@tan scripts]$ bash test.sh

Hello Shell

4、shell环境执行

shell环境执行,指的是在当前的shell环境中执行,可以使用 . 接脚本 或 source 接脚本[tan@tan scripts]$ . test.sh

Hello Shell

[tan@tan scripts]$ source test.sh

Hello Shell

以上就是linux执行shell脚本的四种方式的详细内容了,看完之后是否有所收获呢?如果想了解更多相关内容,欢迎来亿速云行业资讯!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值