Friday, November 11, 2016

Escape filename

x='a real \good %* load of c$rap'
x=$(printf '%q' "$x")
echo $x

will return

a\ real\ \\good\ %\*\ load\ of\ c\$rap



printf "%q" "Maroon 5 - Lost Stars.mp3"
will return
Maroon\ 5\ -\ Lost\ Stars.mp3


Escaping string with  tab and enter

echo  $( printf "%q" "teste   ^M ola" | sed 's/^\$'\''//g;s/'\''$//g')

teste \t \r ola

No comments:

Blog Archive