Concatenate all arguments and wrap them with double quotes

前端 未结 6 1457
广开言路
广开言路 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:38

    You can use "$@" to treat each parameter as, well, a separate parameter, and then loop over each parameter:

    function foo() {
    for i in "$@"
    do
        echo -n \"$i\"" "
    done
    echo
    }
    
    foo bla "hello ppl"
    

提交回复
热议问题