Can't run shellscript with sudo
12,439
Solution 1
Either add a shebang at the first line of your script:
#!/bin/bash
echo "Hallo"
And/or set the executable rights
sudo chmod +x connector.sh
Solution 2
Another possible solution is to call the script in this way:
sh ./connector.sh
you can use any other shell type other than sh
, depends on your code.
Related videos on Youtube
Author by
Casper Rasmussen
Updated on September 18, 2022Comments
-
Casper Rasmussen over 1 year
When I try to run my script like this:
sudo ./connector.sh
It give me this:
sudo: ./connector.sh: command not found
What am I doing wrong?
-
heemayl almost 9 yearsIf your
myscript.sh
callsconnector.sh
, doesconnector.sh
resides in the current directory or in thePATH
? -
Casper Rasmussen almost 9 yearsoh... myscript.sh is connector.sh i just renamed it in the post...
-
heemayl almost 9 yearsWhats the output of
stat -c '%A' myscript.sh
? -
Arronical almost 9 yearsAre trying to execute the script from within the directory containing it?
-
Casper Rasmussen almost 9 yearsThe script is in the /root directory, and im execute the script when im en the /root directory. My script just echo "Hallo";
-
-
A.B. almost 9 yearsOr in this way =) +1
-
Fabby almost 9 yearsThe simple solutions are the best!