我有这个奇怪的问题,我不明白为什么会发生。对于任何 bash 忍者来说,这应该是小菜一碟。
OPTIONS="-auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three'"
unison $OPTIONS a b
我希望这被翻译为...
unison -auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three' a b
......然后工作。但事实并非如此。运行完整命令时,我没有问题,一致就可以了。但是当我运行命令
unison $OPTIONS a b
时,unison 提示:Usage: unison [options]
or unison root1 root2 [options]
or unison profilename [options]
For a list of options, type "unison -help".
For a tutorial on basic usage, type "unison -doc tutorial".
For other documentation, type "unison -doc topics".
unison was invoked incorrectly (too many roots)
我究竟做错了什么?
最佳答案
BASH 常见问题条目 #50:"I'm trying to put a command in a variable, but the complex cases always fail!"
options=(-auto -batch -ignore 'Path one' ...)
unison "${options[@]}" a b
关于Bash 命令引用问题,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14564250/