Why does echo-ing a carriage return from OSX Terminal behave differently than from a bash script?
From Terminal in OSX 10.7.3:
$ echo $SHELL
/bin/bash
$ /bin/bash --version
GNU bash, version 3.2.48(1)-release (x86_64-apple-darwin11)
Copyright (C) 2007 Free Software Foundation, Inc.
$ echo -ne "hello\rbye"
byelo
But I see a different result from test.sh:
#!/bin/bash
echo -ne "hello\rbye"
…running test.sh gives me:
$ ./test.sh
byehello
I was expecting byelo. Why is it different? and how do I correct this?
It had something to do with
#!/bin/shat the top of my script. After I changed it to#!/bin/bash, I saw the expected output.