Search code examples
bashcygwinalias

Using an alias to call a python script


In order to use a python script that is a part of a molecular docking software I have to use a python shell included in the software files. This means that I have to write

pythonsh path/path/script.py parameters

I have tried setting an alias for path/path/script.py in order to call it quicker but bash fails to recognize my alias when it is a part of something like this.

Is there a way to do this?

Note: I'm using cygwin on windows. I don't think this will have any repercussions on the answer (bash is bash right?) but I thought I should disclose that information just in case.

Thanks!


Solution

  • Just alias the whole thing

    alias pshell="pythonsh path/path/script.py"
    

    Or use a function

    pshell() {
      pythonsh path/path/script.py "$@"
    }
    

    Alternatively you could set a variable for the path in a source file, and then use the variable in-line, e.g. in your ~/.bashrc

    pyth="path/path/script.py"
    

    And now you could run it with

    pythonsh $pyth parameters
    

    Note, if the path has a space or escape characters, make sure to quote "$pyth"