Concatenate all arguments and wrap them with double quotes

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

    Use parameter substitution to add " as prefix and suffix:

    function foo() {
        A=("${@/#/\"}")
        A=("${A[@]/%/\"}")
        echo -e "${A[@]}"
    }
    
    foo bla "hello ppl" kkk 'ss ss'
    

    Output

    "bla" "hello ppl" "kkk" "ss ss"
    

提交回复
热议问题