0

我想用复杂的参数执行一个函数

我想以这种方式输入它们(如果可能的话?)

set [-options here] a111 "a222" "a333 a333" "a444"
set [-options here] b111 "b222" "b333 b333" "b444"
set [-options here] c111 "c222" "c333 c333" "c444"

myfunc "$@"

myfunc应该看到

a111 "a222" "a333 a333" "a444" ==> as the first argument with keeping ""
b111 "b222" "b333 b333" "b444" ==> as the second argument with keeping ""
c111 "c222" "c333 c333" "c444" ==> as the third argument with keeping ""

是否可以通过 set 或其他方式做到这一点?怎么做?

顺便说一句,我不想​​使用\"

我也不能使用'(like '"a333 a333"'),因为它不评估 vars

4

1 回答 1

1

如果您希望该值带有引号(这通常是一件奇怪的事情),您需要将它们从 shell 中转义。

$ set -- a111 '"a222"' '"a333 a333"' "\"a444\""
$ c() {
printf argc:%s\\n "$#"
printf argv:%s\\n "$@"
}
$ c "$@"
argc:4
argv:a111
argv:"a222"
argv:"a333 a333"
argv:"a444"
于 2015-02-16T15:43:31.690 回答