繁体   English   中英

如何在Bash Shell脚本中从文件执行命令列表

[英]How can I execute list of commands from a file in Bash Shell Script

我有一个文件“ commands.txt”,其中包含一些命令,例如:

pwd
wc -l commands.txt

当我运行以下命令时,它不执行命令。

export IFS=$'\n' (I did this so that I could avoid breaking up the command line from the file)
for i in `cat commands.txt`; do  $i; done

任何帮助将不胜感激。

关于RSR

由于将IFS设置为\\n ,因此第二行wc -l commands.txt不能正确分词,并且被视为单个命令,而不是后跟参数commands.txt的命令wc 不要设置IFS ,而是使用while循环

while read -r com; 
do 
    $com; 
done < commands.txt

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM