How do I echo one or more tab characters using a bash script? When I run this code
res=' 'x # res = "\t\tx"
echo '['$res']' # expect [\t\tx]
I get this
res=[ x] # that is [<space>x]
How do I echo one or more tab characters using a bash script? When I run this code
res=' 'x # res = "\t\tx"
echo '['$res']' # expect [\t\tx]
I get this
res=[ x] # that is [<space>x]
echo -e ' \t '
will echo 'space tab space newline' (-e
means 'enable interpretation of backslash escapes):
$ echo -e ' \t ' | hexdump -C
00000000 20 09 20 0a | . .|
Using echo to print values of variables is a common Bash pitfall. Reference link: