bash - 使用附加选项或参数运行可执行文件

标签 bash

我正在编写一个 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)。

我的问题是:

  1. 我有followed this question让我的 bash 脚本运行可执行文件。但恐怕我仍然会遇到上面的错误。
  2. 我是否指定了执行文件所需的参数?

最佳答案

我建议你使用

sh -c "$mp2 $myfile -m mymode"

而不仅仅是

"$mp2 $myfile -m mymode"

关于bash - 使用附加选项或参数运行可执行文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55479203/

相关文章:

bash - Hadoop 启动-all.sh 错误 :No such file or directory

linux - 应用程序状态脚本

bash 单行代码用于在最后一个屏幕上打开 `less` 且不包含临时文件

bash - exec-maven-plugin 无法执行 .sh 脚本 : permission denied

linux - 如何重新安装最新的cmake版本?

bash - awk 在 bash -c "somecommand | awk ' {print $2 }'"中不工作

linux - 在 bash 变量中保存 URL 会导致 curl 失败

bash - 在 find -exec 中使用别名

mysql - Linux - Docker MySQL 镜像 - 创建 MYSQL_USER

linux - 将循环的批处理文件转换为循环的 shell 脚本