在文件中有一些多行命令,类似于以下内容:
cd /home/user; ls
在一个bash脚本中,我想要执行这些命令,并在最后一个命令中添加一些参数。例如:
cd /home/user; ls -l *.png
我以为只需要这样做就可以了:
#!/bin/bash
commandLine="$(cat theFileWithCommandInside) -l *.png"
$commandLine
exit 0
但它说:
/home/user;: No such file or directory
换句话说,";"字符不再表示“命令结束”,shell正在尝试在主目录中查找名为"user;"的文件夹...我试图用"&&"替换";",但结果相同。
bash -c ...
。 - Jason Hu