How to substitute quoted, multi-word strings as arguments?

前端 未结 4 1792
一整个雨季
一整个雨季 2020-12-01 21:08

I\'m trying to substitute a string variable, containing multiple quoted words, as a parameter to a command.

Thus, given the following example script (Note the -x in

4条回答
  •  鱼传尺愫
    2020-12-01 22:03

    If you want to pass a variable value as a parameter (99% of cases on SO), simply use proper quoting:

    arg="foo bar"
    command "$arg"
    

    If you want to pass several arguments, use arrays:

    args=("foo bar" "baz ban" bay)
    command "${args[@]}"
    

提交回复
热议问题