Bash命令引用问题

Jor*_*Lis 4 bash quoting

我有这个奇怪的问题,我无法理解为什么会发生.任何bash忍者应该是小菜一碟.

OPTIONS="-auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three'"
unison $OPTIONS a b
Run Code Online (Sandbox Code Playgroud)

我希望这被翻译成......

unison -auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three' a b
Run Code Online (Sandbox Code Playgroud)

......而且只是工作.但事实并非如此.当运行完整命令时,我没有问题,一致就是这样.但是当我运行命令时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)
Run Code Online (Sandbox Code Playgroud)

我究竟做错了什么?

Ign*_*ams 7

BASH FAQ条目#50:"我正在尝试将命令放入变量中,但复杂的情况总是失败!"

options=(-auto -batch -ignore 'Path one' ...)
unison "${options[@]}" a b
Run Code Online (Sandbox Code Playgroud)