0

I get the following error (error.message) when I run the following shell script (myscript.sh).

myscript.sh
#!/bin/bash
cd /path/to/ && node app.js
error.message

/path/to/myscript.sh: line 1: #!/bin/bash: No such file or directory

/path/to/myscript.sh: line 2: node: command not found

I have already run the following command line instructions.

command-line
chmod u+x /path/to/myscript.sh
chmod u+x /path/to/app.js

Also, I know I have node installed because when I run:

node -v

I get back:

v5.5.1

I execute myscript.sh via the following AppleScript:

MyApp.applescript
do shell script "bash /path/to/myscript.sh"

Also: which bash returns /bin/bash

What could be causing this error and how can I fix it?

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207

2 Answers2

0

I fixed the first error:

/path/to/myscript.sh: line 1: #!/bin/bash: No such file or directory

By copying a working .sh file I had on my machine and copy/pasting the code from the old file to the new file.

I'm guessing somehow there was a filetype issue or discrepancy despite the fact that I used a .sh extension in the file name.

In the future, I will double check the file type in my Finder utility (Max OS X v10.10.1).

However, I am still seeing the second error:

/path/to/myscript.sh: line 2: node: command not found

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207
0

Credit goes to @HeadCode and @mh-cbon for helping me figure this out with their comments.

I solved the second problem by running:

myshell.sh
#!/bin/bash
path/to/node path/to/app.js

where path/to/node was found by running

command-line
which node

and path/to/app.js is the actual file tree path to app.js. (In other words, different from path/to/node.)

Let Me Tink About It
  • 15,156
  • 21
  • 98
  • 207