Escaping characters

Basic types / Strings

#inside double quotes the \ escapes only $ ` " \ and the line end
strV="She said \"Hello!\" to me."
#strV is "She said "Hello!" to me."

price="It costs \$5"
#price is "It costs $5"

#inside single quotes nothing is special, and a ' can not be there:
#close the quotes, add \' and open them again
it='It'\''s mine'
#it is "It's mine"

#$'…' understands the C escapes:
#\t a tab, \n a new line, \r a carriage return,
#\' a single quote, \" a double quote, \\ a backslash,
#\x41 a character by its hex code ('A')
path=$'C:\\Temp'
#path is "C:\Temp"
letter=$'\x41'
#letter is "A"

#printf %q escapes a string so that bash can read it back
printf -v quoted '%q' "a b"
#quoted is "a\ b"

echo "strV is $strV"
echo "price is $price"
echo "it is $it"
echo "path is $path"
echo "letter is $letter"
echo "quoted is $quoted"