Echo tab characters in bash script

Viewed 586427

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]
10 Answers
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                                       | . .|

You can also try:

echo Hello$'\t'world.

Put your string between double quotes:

echo "[$res]"

you need to use -e flag for echo then you can

echo -e "\t\t x"
Related