Concatenate all arguments and wrap them with double quotes

前端 未结 6 1467
广开言路
广开言路 2020-12-15 05:52
function foo() {
A=$@...
echo $A
}

foo bla \"hello ppl\"

I would like the output to be:
\"bla\" \"hello ppl\"

What do I need to do in

6条回答
  •  無奈伤痛
    2020-12-15 06:37

    @msw has the right idea (up in the comments on the question). However, another idea to print arguments with quotes: use the implicit iteration of printf:

    foo() { printf '"%s" ' "$@"; echo ""; }
    
    foo bla "hello ppl"
    # => "bla" "hello ppl"
    

提交回复
热议问题