Bash命令引用问题
我有一个奇怪的问题,我不明白为什么会发生。这对任何一个bash忍者来说都应该是小菜一碟Bash命令引用问题,bash,quoting,Bash,Quoting,我有一个奇怪的问题,我不明白为什么会发生。这对任何一个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 …只要工作。但事实
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对此没有问题。但当我运行命令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:
现在可以了。下次提问之前,我会先看看这个常见问题。非常感谢。
options=(-auto -batch -ignore 'Path one' ...)
unison "${options[@]}" a b