Words of the form $'string' are treated specially. The word expands to string, with backslash-escaped characters replaced as specified by the ANSI C standard. Backslash escape sequences, if present, are decoded as follows:
- \a: alert (bell)
- \b backspace
- \e an escape character
- \f form feed
- \n new line
- \r carriage return
- \t horizontal tab
- \v vertical tab
- \\: backslash
- \' single quote
- \nnn the eight-bit character whose value is the octal value nnn (one to three digits)
- \xHH: the eight-bit character whose value is the hexadecimal value HH (one or two hex digits)
- \cx a control-x character
The expanded result is single-quoted, as if the dollar sign had not been present.
variable="First"$'\n' variable=$variable"Second"$'\n' echo "$variable"
The echo command must have its parameter between parenthesis to show the newlines in a variable
# Variable TEST=$`Hello\nNico` echo "$TEST" # or Text echo -e "Hello\nNico"
!!!! Bad/wrong !!!!
# Bad echo $TEST
To see the backslash character, you need to use the cat command.
echo $'Hello\tWorld\vHello \nHello ' | cat -vte
- for $'Hello\tWorld\vHello \nHello '
- the cat options:
- v: show non-printing
- T: show tabs
- E: show ends
Hello^IWorld^KHello $ Hello $
- ^I represents a horizontal tab
- ^K represents a vertical tab
- $ represents an end-of-line
echo $'\t' | sed 's/ /·/g;s/\t/￫/g;s/\r/§/g;s/$/¶/g'