How to echo a Tab or Other Special Characters in Linux

I’m working on a bash script that I want to insert some text into a file. So I’m using the echo command to do this, like so:


echo “hello, world” > myfile.txt

This works just great. Now I want to insert a special character into the file. So I need to do two things: 1) escape special characters and 2) append rather than write to the file. The special character I want to insert is a tab, which is represented as \t. In order to do this, you have specify the -e parameter when you call echo. Like so:


echo -e “before\tafter” >> myfile.txt

The myfile.txt file should contain something like this now:

hello, world
before    after

Leave a Reply