linux运行文件命令有哪些-世界新要闻

来源:php中文网 | 2023-01-28 18:47:31 |

本教程操作环境:linux7.3系统、Dell G3电脑。

创建文件

vi test.txt# 按i切换insert模式# 输入文本#!/bin/bashecho "Hello world!!!"echo $$ # 打印当前进程idecho $test

执行(运行)文件的方式


(相关资料图)

1、 使用source执行脚本

test=100source test.txt

输出:

Hello world!!!37790100

使用的为当前bash

2、 使用.执行脚本

. test.txt Hello world!!!37790100

使用的为当前bash

3、 使用bash执行脚本

bash test.txt Hello world!!!47733

进程id更新了,且未获取到变量test的值,因为启动了子进程的bash执行脚本。

4、 使用./file执行脚本

注意:此种方式首先得给脚本添加执行权限 chmod +x test.txt

./test.txt Hello world!!!47758

进程id更新了,且未获取到变量test的值,因为启动了子进程的bash执行脚本。

推荐学习:Linux视频教程

以上就是linux运行文件命令有哪些的详细内容,更多请关注php中文网其它相关文章!

关键词: linux