I am trying to execute sudo command inside a bash script.
#!/bin/bash sudo node app.js
and it throws me :
sudo: node: command not found
If I try to execute only node app.js (without sudo ),it runs ok.
If I try to just run
sudo -h , it prints the sudo help.
But , when I am trying the
sudo node app.js it throws me the error.
node is on a non-standard path, or at least not on root’s path. There are a couple of ways around this.
Use the full path to
Find the full path using
If say it’s in
sudo /home/user/bin/node app.js
Or as @UlrichSchwarz suggested you can combine the two with command substitution:
sudo $(which node) app.js
Remember the user you
sudoto needs read/execute permissions on the location, not as much of an issue when you
-Eoption to preserve environment variables
sudo -E node app.js
This will keep your
You can see the
sudomanpage for more info: http://linux.die.net/man/8/sudo