1

I have git for windows 2.5.2 (64-bit version), downloaded from: https://git-scm.com/download/win

All I wanted was to create a .sh that would commit/push my work for me. I wrote the script and when I try to run it I get an error like:

"#!/bin/sh: No such file or directory"

As you can see I have my PATH set for my git-bash and my git-sh (also for my sh.exe and my bash.exe)

PATH-> "C:\Program Files\Git\bin\;C:\Program Files\Git\mingw64\;"

I also have my ~/.bash_profile:

if [ -f ~/.bashrc ]; then . ~/.bashrc; fi

My ~/.profile:

#!/bin/sh.exe
#
# Get the aliases and functions
#

if [ -f ${HOME}/.bashrc ]
then
  . ${HOME}/.bashrc
fi

  export CVS_RSH="ssh"
  export EDITOR="/usr/bin/vim"
  export HISTSIZE="500"
  export PATH="${HOME}/bin:${PATH}"

And my simple script.sh:

#!/bin/sh.exe

P_J="Le/Prjt/swks/games"
GITLAB_USER='myuser'
GITLAB_PASSWORD='mypass'
P_JG='G Select'
NAME_OF_REP='g-select'

cd $P_J || EXIT
cd "$P_JG" || EXIT
#git add -A
#git commit -m "$(date)"
#git push https://$GITLAB_USER:[email protected]/$GITLAB_USER/$NAME_OF_REP.git

From my Git-Bash, here is an "echo $PATH":

$ echo $PATH /c/Users/UserP/bin:/mingw64/bin:/usr/local/bin:/usr/bin:/bin:/mingw64/bin:/usr/bin:/c/ProgramData/Oracle/Java/javapath:/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/c/Windows/system32:/c/Windows:/c/Windows/System32/Wbem:/c/Windows/System32/WindowsPowerShell/v1.0:/c/Program Files/Java/jre1.8.0_51/bin:/c/Program Files (x86)/Android/android-sdk/platform-tools:/bin:/mingw64:/usr/bin/vendor_perl:/usr/bin/core_perl

As I said, when opening git-bash and running my simple .sh I get this error:

./script.sh: line 1: #!/bin/sh.exe: No such file or directory

The problem seems to be when creating a variable on my shellscript. Does anyone have any idea of what may be causing this problem?

Thanks in advance!

5
  • I don't understand why it fails on line 1, but every one of your variable assignments looks malformed; in Bourne shell scripting, you cannot insert arbitrary white space around the = operator. It must be VARNAME=VALUE, whith no unquoted whitespace anywhere, (and quoted whitespace only permitted within VALUE). Commented Sep 15, 2015 at 7:02
  • I've never used the git-sh/git-bash fork of MSYS, but I do know that for MinGW.org's MSYS, we always caution very strongly against installing into any subdirectory of "Program Files", (or any other with whitespace in its absolute path name). See, that space is sure to turn around and bite you, eventually; I wonder is it doing just that, in this case? Commented Sep 15, 2015 at 9:26
  • Hey @Keith, thank you for your answer! The spaces were, actually, a mistake of mine when copying the code here. My script didn't have that, so I edited my original post and removed those spaces. Secondly, I tried to reinstall Git on a non-spaced folder (actually I did install it on C:) and, unfortunately I'm still getting the same error. =( Commented Sep 16, 2015 at 16:22
  • @jthill: "Yank the .exe". Agreed, we don't normally specify .exe in the shebang, but with MSYS, from MinGW.org, on 32-bit Windows7, it makes no difference either way -- both #!/bin/sh and #!/bin/sh.exe WJFFM. Maybe the git port, for 64-bit windows has broken this? Commented Sep 16, 2015 at 20:18
  • @MarceloPetrucelli, is your login shell properly initialized? How did you start it? What is the output from type sh.exe? Commented Sep 16, 2015 at 20:23

2 Answers 2

3

./script.sh: line 1: #!/bin/sh.exe: No such file or directory

FWIW this error is usually caused by the abomination called the UTF8-BOM.

The character "Zero width no-break space" is used as a "Byte order mark" in UTF16. Several windows editors (notepad IIRC) also put this invisible (and useless) character at the start of a file encoded in UTF8.

If you have "Notepad++" the encoding menu item lets you choose between UTF8 and UTF8-BOM, switch the file to the former.

Sign up to request clarification or add additional context in comments.

Comments

0

How are you trying to run it? All I need to do at a command prompt is drag the file into the MINGW64 window so the file path and name appear, press enter, and it runs.

But if I preceed the file name in the command line with sh, I get that "#!/bin/sh.exe: No such file or directory" or similar that you mention.

That is:

$ [file path]

works.

$ sh [file path]

doesn't.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.