Adding a tab in a Shell script

djowinz picture djowinz · Jul 20, 2012 · Viewed 21.9k times · Source

So I have an extremely simple shell script, where it inputs an IP address and a domain name in the hosts file of a person's computer. For "development purposes only!" it works fine, it just inputs the IP address and domain name like so

192.168.53.215dev.env.os 192.168.53.215dev.source.os

Where I want it to input it like this:

192.168.53.215 dev.env.os 192.168.53.215 dev.source.os

So basically I want it to add space between the IP address and the domain name, unfortunately I can't really figure it out. Any help would be appreciated, this is a simple script though and shouldn't be cluttered with an over complicated script. Please keep it simple and explain exactly what you're doing I would like to learn it not have it done for me thanks!

Here is the code:

do shell script "/usr/bin/printf \"\\n# Add #####'s ip for Sourcebox\\n192.168.53.215\\dev.env.os\\n192.168.53.215\\dev.source.os\\n\" >> /etc/hosts; /usr/bin/dscacheutil -flushcache" with administrator privileges

Answer

El Yobo picture El Yobo · Jul 20, 2012

Using the -e flag with echo in a bash script will allow you to output tabs.

echo -e "this\thas\ttabs"