I have a python script which takes various options from the command line
e.g.
-runs with gui
python myscript.py -gui
-runs without requiring user prompts
python myscript.py -aut
-runs with input data taken from input.py
python myscript.py input.py
-and combinations of the above e.g. runs automatically taking input from input.py
python myscript.py -aut input.py
I would like to be able to call this from anywhere on my linux box. How can I do this? I have tried aliasing this in my .bashrc file, but using this method it is unable to accept any of the input options. I have also tried
export PATH=$PATH:/path/to/folder/above_myscript/
but this only recognises the command if I type myscript, not python myscript . Typing just myscript obviously is unable to run the python script.
I have also tried writing a shell script which I could call.
#!/bin/bash
#file: myscript.sh
python '/path/to/folder/above_myscript/myscript.py'
However, again I am also unable to pass any options to it. What is the best solution to this problem?
If you add
#!/usr/bin/env python
to the top of your myscript.py file and runchmod +x myscript.py
on it you should be able to runmyscript.py
without needing to putpython
before it. This should let you use thePATH
changing method you had before.