Bash quoted array expansion

前端 未结 6 1071
借酒劲吻你
借酒劲吻你 2021-01-31 02:57

WHen I write a bash program I typically construct calls like follows:

declare -a mycmd=( command.ext \"arg1 with space\" arg2 thing etc )

\"${mycmd[@]}\" || ech         


        
6条回答
  •  情深已故
    2021-01-31 03:11

    How about declare -p quotedarray?

    -- edit --

    Acctually, declare -p quotedarray will satisfy you purpose well. If you insist on the output format of the result, then I have a small trick would do the work, but just for the indexed array not associative one.

    declare -a quotedarray=(1 2 "3 4")
    temparray=( "${quotedarray[@]/#/\"}" ) #the outside double quotes are critical
    echo ${temparray[@]/%/\"}
    

提交回复
热议问题