Search code examples
pythonbashshellgetopt

How to run bash script with getopt included in python?


I am running a script in the ubuntu terminal and it works fine.

./run_script2.sh -b ./exercises/13_caching.py 

I want to run the same script in python os or subprocess but I am getting an error :

./run_script2.sh: line 36: getopt: command not found

On line 36 I have :

opts=`getopt -o f:b:ia:p:d:h --long no-status-srv --long status-port: -- "$@"`

How can I run this script as I run in the terminal using python?


Solution

  • getopt is not in your PATH and then not found.

    Try:

    opts=$(/usr/bin/getopt -o f:b:ia:p:d:h --long no-status-srv --long status-port: -- "$@")
    

    assuming /usr/bin/ is where getopt is located.