Turn an application or script into a shell command

后端 未结 6 1849
走了就别回头了
走了就别回头了 2021-02-06 11:11

When I want to run my python applications from commandline (under ubuntu) I have to be in the directory where is the source code app.py and run the application with command
<

6条回答
  •  野趣味
    野趣味 (楼主)
    2021-02-06 11:43

    A solution some what different from the ones mentioned here: Use an alias.

    alias app='python /path/to/app.py'
    

    Add the above line to your ~/.bashrc or ~/.bash_login file (or preferably to ~/.bash_aliases if you are on Ubuntu). Then you can simply use your script as a command line tool with app.

    No need to add a shebang (thereby modifying your existing Python script), no need to make the script executable and no need to change your PATH.

提交回复
热议问题