gpt4 book ai didi

bash - 我如何 'exec' 像这样的 bash 命令,其中一个选项是多字的?

转载 作者:行者123 更新时间:2023-11-29 09:27:42 25 4
gpt4 key购买 nike

在命令行上,我可以这样运行我的二进制文件:

theBinary_exe -q 'more than one word' -f foo -b bar

当我将其放入 bash 脚本并运行该脚本时,一切正常。但是如果我在脚本中这样做:

CMD="theBinary_exe -q 'more than one word' -f foo -b bar"
exec $CMD

'q' 参数仅将第一个单词传递给可执行文件。我也尝试过使用\",但没有成功。当我使用 exec 时,是否可以使用包装来防止这种情况发生?

最佳答案

Do not use a regular parameter .

使用数组:

args=( -q 'more than one word' -f foo -b bar)
theBinary_exe "${args[@]}"

关于bash - 我如何 'exec' 像这样的 bash 命令,其中一个选项是多字的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35158163/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com