加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > Linux > 正文

linux – 在终端中运行文本文件

发布时间:2020-12-13 16:57:01 所属栏目:Linux 来源:网络整理
导读:有谁知道是否有办法在 shell中自动运行一个命令列表(来自文本文件)? 我需要运行很多脚本(大约1000个).脚本在python中,每个脚本有两个参数(dir_#和示例#) 我制作的文本文件看起来像这样…… python /home/name/scripts/get_info.py dir_1 sample1 python /ho
有谁知道是否有办法在 shell中自动运行一个命令列表(来自文本文件)?

我需要运行很多脚本(大约1000个).脚本在python中,每个脚本有两个参数(dir_#和示例#)

我制作的文本文件看起来像这样……

python /home/name/scripts/get_info.py dir_1 sample1
     python /home/name/scripts/get_info.py dir_2 sample2
     python /home/name/scripts/get_info.py dir_3 sample3
     python /home/name/scripts/get_info.py dir_4 sample4
     ...

所以,我希望将这个文本文件作为参数传递给终端中的命令,可以自动完成工作…

提前致谢,

佩希

解决方法

这被称为“shell脚本”.

将其添加到文件顶部:

#!/bin/sh

然后执行以下命令:

chmod +x filename

然后像程序一样执行:

./filename

或者,您可以直接执行shell,告诉它执行文件中的命令:

sh -e filename

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读