Outputting bash-quoted array from bash Outputting bash-quoted array from bash unix unix

Outputting bash-quoted array from bash


Your last example of expected output is the exact output of

$ arr=( foo "quz bar" "wibble 'smoo' \"blep\"")$ printf "%q " "${arr[@]}"foo quz\ bar wibble\ \'smoo\'\ \"blep\"

The %q placeholder in printf outputs its string in quoted form, ready for use as input.