1

I have a simple bash shell script I'm running under Git Bash in Windows 10. If I include the usual first line:

#!/bin/bash

I get the error:

bash: #!/bin/bash: No such file or directory

If I omit that line, I get the error:

bash: $'\357\273\277': command not found

I found some commentary online that $'\357\273\277' is a byte-order mark but I don't know what to do with that information. How can I correct this?

Edit: I realize there is no /bin/bash in a Windows file system, but is there an equivalent that should be used for Git Bash?

  • 1
    You should save the file with text editor settings that exclude the byte order mark. How was the file created? – g_bor Sep 19 '19 at 21:52
  • 1
    @g_bor Bingo. I saved it with Visual Studio. If you'll add this as an answer, I'll accept it. Saving it without BOM allows it to work without error. How to do that is described here: https://stackoverflow.com/questions/5406172/utf-8-without-bom/5411486#5411486 – Anon_unique Sep 20 '19 at 14:14
  • Thanks for coming back to me. I added this as an answer. – g_bor Sep 20 '19 at 18:06

3 Answers3

2

The text editor saved the file with a BOM that is causing an error. In most editors you find a setting to exclude the byte order mark on save. For instructions on how to do that on Visual Studio, see: UTF-8 without BOM

g_bor
  • 1,077
  • 6
  • 14
0

Try this for your first line in your script:

#!/usr/bin/bash

I also have Git Bash installed under Windows and when I did a "which bash" I got "/usr/bin/bash".

Dean
  • 939
  • 10
  • 30
  • I see that for "which bash" also but still get the error: bash: #!/usr/bin/bash: No such file or directory – Anon_unique Sep 19 '19 at 21:45
  • Can you post the actual script? I am doing some testing in my Git Bash and it seems to work fine for me but it would be better if I could debug using your actual script. – Dean Sep 19 '19 at 21:53
0

seems like bash is not located in directory you are importing from, make sure you bash is installed in /bin directory only or you can search it by

locate bash

it will give you exact location of bash and you can use that

example:- if you bash located in /tmp/bash then you can import it like

#!/tmp/bash

or you can check if bash is even installed or not using

cat /etc/shells
Ankush Sahu
  • 578
  • 7
  • 13