Reputation: 178
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!
Upvotes: 1
Views: 7481
Reputation: 2334
./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.
Upvotes: 3
Reputation: 653
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.
Upvotes: 0