pei*_*ixe 7 linux terminal command-line list
有没有人知道是否有办法在shell中自动运行一个命令列表(来自文本文件)?
我需要运行很多脚本(大约1000个).脚本在python中,每个脚本有2个参数(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
...
Run Code Online (Sandbox Code Playgroud)
所以,我希望将这个文本文件作为参数传递给终端中的命令,可以自动完成工作......
提前致谢,
佩希
Fli*_*mzy 20
这被称为"shell脚本".
将其添加到您的文件顶部:
#!/bin/sh
Run Code Online (Sandbox Code Playgroud)
然后执行以下命令:
chmod +x filename
Run Code Online (Sandbox Code Playgroud)
然后像程序一样执行:
./filename
Run Code Online (Sandbox Code Playgroud)
或者,您可以直接执行shell,告诉它执行文件中的命令:
sh -e filename
Run Code Online (Sandbox Code Playgroud)
小智 6
要么使文件可执行:
chmod u+x thefile
./thefile
Run Code Online (Sandbox Code Playgroud)
或将其作为 sh 的参数运行:
sh thefile
Run Code Online (Sandbox Code Playgroud)