Skip to content
Advertisement

Create terminal name for execute python script in Ubuntu

I have a python file in: ‘/home/username/scripts/pyscript’ and I want set a word for execute directly this script.

I want do this “python3 /home/username/scripts/pyscript/main.py arg1 arg2” but looks like this “myscript arg1 arg2”

Is this posible? Thank you anyway.

Advertisement

Answer

Finally I solver with the help of @pierpaciugo I add a alias at the end of the .bashrc for make it persistent:

alias create='bash /home/username/Programming/Python/GithubAPI/script.sh'

I couldn’t use only alias because I have my python dependencies on a virtual environment so if I try this i could not add params to my python script.

For that I create this bash script:

#!/bin/bash

source /home/username/Programming/Python/GithubAPI/venv/bin/activate && python3 /home/username/Programming/Python/GithubAPI/main.py $@ && deactivate

Now I can write “create param1 param2” and it works. I am using all global paths but could be a good idea add the script in a folder in my PATH.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement