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.

Share:
12,439

Related videos on Youtube

Casper Rasmussen
Author by

Casper Rasmussen

Updated on September 18, 2022

Comments

  • Casper Rasmussen
    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
      heemayl almost 9 years
      If your myscript.sh calls connector.sh, does connector.sh resides in the current directory or in the PATH ?
    • Casper Rasmussen
      Casper Rasmussen almost 9 years
      oh... myscript.sh is connector.sh i just renamed it in the post...
    • heemayl
      heemayl almost 9 years
      Whats the output of stat -c '%A' myscript.sh ?
    • Arronical
      Arronical almost 9 years
      Are trying to execute the script from within the directory containing it?
    • Casper Rasmussen
      Casper Rasmussen almost 9 years
      The script is in the /root directory, and im execute the script when im en the /root directory. My script just echo "Hallo";
  • A.B.
    A.B. almost 9 years
    Or in this way =) +1
  • Fabby
    Fabby almost 9 years
    The simple solutions are the best!