Make your commandline scripts global
Very occasionally I venture into the world of commandline scripts. Every now and then I get an idea about something I think I can automate or make more efficient by writing a script.
Then I usually fail at writing the script. However, sometimes I succeed.
But then what?
I have to remember where the script is and how to run it.
No longer. I now know how to make the script global and give it a short name so it's easier to run.
The steps are:
- Create script (and test it works)
- Make sure it is executable (
chmod +x script_name
) - Create a folder for all your scripts (e.g.
~/bin
) - Add folder to path (e.g. in .zshrc add
export PATH=$HOME/bin:$PATH
) - Add an alias for your script (e.g.
alias myscript=my_script.sh
)