我正在编写一个 bash 脚本 Test.sh
,旨在执行 另一个脚本
(Linux 可执行文件):
#!/bin/bash -l
mp1='/my/path1/'
mp2='/my/path2/anotherscript'
for myfile in $mp1*.txt; do
echo "$myfile"
"$mp2 $myfile -m mymode"
echo "finished file"
done
请注意,anotherscript
采用参数 $myfile
和选项 -m mymode
。
但我收到文件未找到错误(表示 Test.sh: line 8:/my.path2/anotherscript: No such file or directory
)。
我的问题是:
- 我有followed this question让我的 bash 脚本运行可执行文件。但恐怕我仍然会遇到上面的错误。
- 我是否指定了执行文件所需的参数?
最佳答案
我建议你使用
sh -c "$mp2 $myfile -m mymode"
而不仅仅是
"$mp2 $myfile -m mymode"
关于bash - 使用附加选项或参数运行可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55479203/