# Built as an answer to the question in https://stackoverflow.com/questions/47563387/bash-unescape-string/47563868?noredirect=1#comment107466563_47563868
buildInput(){
printf'%s\n' \
'Quoted phrase: "two words"' \
'Two tabs: <\t\t>' \
'Two backslashes: \\\\'
}
hdr(){printf--'------\n-- %s\n'"$@"; }
hdr 'Original stream:'
buildInput
hdr 'Desired output:'
printf'%b\n'"$(buildInput)"
hdr 'Original proposal:'
buildInput |xargs-I{}printf'%b\n'{}
hdr 'Without -I {}:'
buildInput |xargsprintf'%b\n'
hdr 'Correct output only after using -d:'
buildInput |xargs-d $'\n'printf'%b\n'
hdr '...or using -0, transforming the input to be NUL-delimited:'
------
-- Original stream:
Quoted phrase: "two words"
Two tabs: <\t\t>
Two backslashes: \\\\
------
-- Desired output:
Quoted phrase: "two words"
Two tabs: < >
Two backslashes: \\
------
-- Original proposal:
Quoted phrase: two words
Two tabs: <tt>
Two backslashes: \
------
-- Without -I {}:
Quoted
phrase:
two words
Two
tabs:
<tt>
Two
backslashes:
\
------
-- Correct output only after using -d:
Quoted phrase: "two words"
Two tabs: < >
Two backslashes: \\
------
-- ...or using -0, transforming the input to be NUL-delimited:
Quoted phrase: "two words"
Two tabs: < >
Two backslashes: \\