简体   繁体   中英

Error running shell script using bash and node.js

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
do shell script "bash /path/to/myscript.sh"

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?

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

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
which node

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.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM