tags:

views:

52

answers:

2

when I run it in the terminal (bash)

echo -e ."\c"

prints out . and suppresses the newline.

When I run the following script (all the code)

echo -e ."\c"
echo -e ."\c"

it prints out .. and suppresses the newlines.

when I run it inside a script with the shebang (!#/bin/sh), it prints out -e . -e . and suppresses the newline.

Why? and how can I prevent this?

EDIT: I want to prevent the -e's from printing out, so my output should be . .

+1  A: 

you need to give the absolute path to echo if your shebang line is invoking sh. Or just changes the shebang to use bash.

ennuikiller
+1  A: 

change your script shebang to #!/bin/bash instead of #!/bin/sh and see if it works

ghostdog74
or use /bin/echo if you want leave shebang untouched
shuvalov
changing /bin/sh is safer since there are things that won't work with sh if used in bash.
ghostdog74
given that I wrote and tested the script using sh, is it possible that something may break while using bash? (it's moot now, since everything works after changing to bash)
piggles
depends on your distribution, /bin/sh may be "aliased" to the old bourne shell, or sometimes to dash, and sometimes to bash, etc. Bash is a superset of bourne, so if you write in bash and bring your script to run bourne, you might have problems. see also http://en.wikipedia.org/wiki/Shebang_%28Unix%29 for reference. Its still best to explicitly specify which shell you are using
ghostdog74