4

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
Henk Langeveld
  • 8,088
  • 1
  • 43
  • 57
djowinz
  • 356
  • 1
  • 4
  • 17
  • You phrased your original question as a pure shell question, and only the code sample hinted at the fact that your calling the shell from another framework (apparently applescript). Please rephrase the question and provide a little more detail about your context. – Henk Langeveld Aug 03 '12 at 09:49

2 Answers2

10

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

echo -e "this\thas\ttabs"
El Yobo
  • 14,823
  • 5
  • 60
  • 78
  • This was the output after compiled # Add Dyllen's ip for Sourcebox 192.168.53.215echo -e dev.engage.os 192.168.53.215echo -e dev.source.os If I put echo -e "blah" the above code with the string the way that it is, it's inside an identifier which isn't allowed. This would normally work if the code wasn't in a string. Could you use an example of this in my above code somewhere. I seem to be missing exactly what you're saying. Thank You! – djowinz Jul 20 '12 at 20:47
  • It looks like you're writing this for MacOS, which I'm not too sure about. I would imagine that you can wrap the outer string of yours in single quotes instead of doubles and it should work fine; this would disable the interpolation of \t until executed by the inner echo/printf statement. – El Yobo Jul 20 '12 at 21:11
1

The printf can be used as below mentioned for getting tab space

printf "\t"

enter image description here

Jose Kj
  • 2,912
  • 2
  • 28
  • 40