1

I have the following script in my user's bin directory; let's pretend the filename is 'myScript':

#!/bin/bash

python3 /myPath/myProgram.py "$@"

From the commandline, if I type myScript, it launches my myProgram.py. If I type sudo myScript, however it gives me this error: sudo: myProgram: command not found.

Why doesn't this work? How can I make it work?

Thanks!

1 Answers1

5

You probably need to run the script like:

  • sudo /path/to/myScript
  • sudo ./myScript (if the script is in the current directory)

The reason you get command not found is the script is not in the current user's PATH directory. However, using sudo runs it as a different user - root (compare echo $PATH and sudo -i then echo $PATH to see). So of you want to add it to the root user's PATH:

  • Copy it to /usr/local/bin, /usr/bin/ or another direcotry already in the root's PATH
  • Add the directory to the PATH, but do it as root (carefully).
Wilf
  • 30,732