Text - Non-printing Character (Tabulation, New Line, ) in bash
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:
The expanded result is single-quoted, as if the dollar sign had not been present.
var variable=$'TextWithTab\tInBetween'
variable="First"$'\n'
variable=$variable"Second"$'\n'
echo "$variable"
First
Second
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"
Hello
Nico
!!!! Bad/wrong !!!!
# Bad
echo $TEST
Hello Nico
To see the backslash character, you need to use the cat command.
echo $'Hello\tWorld\vHello \nHello ' | cat -vte
where:
Output:
Hello^IWorld^KHello $
Hello $
where:
Shell Data Processing - Sed (Stream editor)
echo $'\t' | sed 's/ /·/g;s/\t/→/g;s/\r/§/g;s/$/¶/g'