0

I recently took a MacBook. I am trying to do some shell programs on my mac. I changed the shell to bash in my mac. When I started executing the shell scripts, I found echo -n is not working as expected. Please help me if I missed any particular settings or so...

In the terminal window (it is working fine):

$ echo "Hello.."
Hello..
$ echo -n "Hello.."
Hello..$ 

In test.sh file:

#!/bin/bash
echo -n "Hello.."

Output:

$ sh test.sh 
-n Hello..
Benjamin W.
  • 46,058
  • 19
  • 106
  • 116
srinivas amara
  • 155
  • 1
  • 10
  • If you want to use Bash features, use `bash test.sh` — running `sh test.sh` uses Bash in POSIX mode, which means many Bash features either don't work or don't work the same (always assuming `/bin/sh` is a link to `/bin/bash` or similar; if `/bin/sh` is a link to `/bin/dash` or another shell, you may get different behaviour again. This is mostly explained in the duplicate question. – Jonathan Leffler Jan 16 '20 at 03:49
  • Thank you Benjamin. Got it. – srinivas amara Jan 17 '20 at 18:11

0 Answers0