I am making an NW.js app on macOS, and want to run the app in dev modeby double-clicking on an icon.In the first step, I'm trying to make my shell script work.
Using VS Code on Windows (I wanted to gain time), I have created a run-nw
file at the root of my project, containing this:
#!/bin/bashcd "src"npm installcd .../tools/nwjs-sdk-v0.17.3-osx-x64/nwjs.app/Contents/MacOS/nwjs "src" &
but I get this output:
$ sh ./run-nw: command not found : No such file or directory : command not found : No such file or directory Usage: npm <command>where <command> is one of: (snip commands list)(snip npm help)npm@3.10.3 /usr/local/lib/node_modules/npm : command not found : No such file or directory : command not found
Some things I don't understand.
- It seems that it takes empty lines as commands.In my editor (VS Code) I have tried to replace
\r\n
with\n
(in case the\r
creates problems) but it changes nothing. - It seems that it doesn't find the folders(with or without the
dirname
instruction),or maybe it doesn't know about thecd
command ? - It seems that it doesn't understand the
install
argument tonpm
. - The part that really weirds me out, is that it still runs the app(if I did an
npm install
manually)...
Not able to make it work properly, and suspecting something weird withthe file itself, I created a new one directly on the Mac, using vim this time.I entered the exact same instructions, and... now it works without anyissues.
A diff
on the two files reveals exactly zero difference.
What can be the difference? What can make the first script not work? How can I find out?
Update
Following the accepted answer's recommendations, after the wrong lineendings came back, I checked multiple things.It turns out that since I copied my ~/.gitconfig
from my Windowsmachine, I had autocrlf=true
, so every time I modified the bashfile under Windows, it re-set the line endings to \r\n
.
So, in addition to running dos2unix
(which you will have toinstall using Homebrew on a Mac), if you're using Git, check your.gitconfig
file.