Linux 在终端中运行文本文件

Linux 在终端中运行文本文件,linux,list,command-line,terminal,Linux,List,Command Line,Terminal,有人知道有没有办法在shell中自动运行命令列表(从文本文件) 我需要运行很多脚本(大约1000个)。脚本采用python语言,每个脚本有2个参数(dir_35;和sample#) 我制作的文本文件如下所示 python /home/name/scripts/get_info.py dir_1 sample1 python /home/name/scripts/get_info.py dir_2 sample2 python /home/name/scripts/g

有人知道有没有办法在shell中自动运行命令列表(从文本文件)

我需要运行很多脚本(大约1000个)。脚本采用python语言,每个脚本有2个参数(dir_35;和sample#)

我制作的文本文件如下所示

     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
     ...
所以,我希望将这个文本文件作为参数传递给终端中的一个命令,可以自动完成这项工作

提前感谢,

peixe

这就是所谓的“shell脚本”

将以下内容添加到文件顶部:

#!/bin/sh
sh -e filename
然后执行以下命令:

chmod +x filename
然后像程序一样执行它:

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

#!/bin/sh
sh -e filename

使文件可执行:

chmod u+x thefile
./thefile
或者将其作为sh的参数运行:

sh thefile

您可以编写shell脚本:

#! /bin/sh

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文件:

source filename

您正在查找的命令是
source
。简单地使其可执行是行不通的,除非第一行包含#/bin/sh这不是真的,至少在bash中不是这样。也许在bash中不是这样,但我不认为我们可以假设每个人都在使用bash——你自己的答案并不是假设在“sh thefile”中是这样的:)好吧,脚本只需要这个指令来确保使用特定的shell,而不是强制的。我不明白,为什么这会被否决。。。这两种类型都符合需要,特别是当您还需要为会话定义一些变量时