且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何将引用的参数传递给另一个程序

更新时间:2023-11-09 23:31:04

使用数组;这就是为什么引入它们的原因.

Use an array; this is why they were introduced.

FOO="ghi"
# Contains one element, but not the literal quotes
DEFAULTS=(--param="abc def $FOO")
# command gets 1 argument, the single element of the array
/some/command "${DEFAULTS[@]}"

# Two elements
DEFAULTS=(--param="abc def $FOO" --other="foo bar")
# command gets 2 arguments
/some/command "${DEFAULTS[@]}"