Bash命令引用问题 [英] Bash command quoting issue

查看:87
本文介绍了Bash命令引用问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个奇怪的问题,我不明白为什么会这样.对于任何bash忍者来说,这都是小菜一碟.

I have this weird issue, I can't understand why is happening. It should be a piece of cake for any bash ninja.

OPTIONS="-auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three'"
unison $OPTIONS a b

我希望将其翻译为...

I expected this to be translated as...

unison -auto -batch -ignore 'Path one' -ignore 'Path two' -ignore 'Path three' a b

...然后工作.但事实并非如此.当运行完整的命令时,我没有问题,可以统一使用.但是,当我运行命令unison $OPTIONS a b时,一致抱怨:

...and just work. But it doesn't. When running the full command, I have no problems, unison is ok with that. But when I run the command unison $OPTIONS a b, unison complains:

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正在尝试将命令放入变量中,但复杂的情况总是会失败!"

BASH FAQ entry #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命令引用问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆