Colmjude

/ notes
Notes
A collection of thoughts, things I've learnt and things I want to remember

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:

  1. Create script (and test it works)
  2. Make sure it is executable (chmod +x script_name)
  3. Create a folder for all your scripts (e.g. ~/bin)
  4. Add folder to path (e.g. in .zshrc add export PATH=$HOME/bin:$PATH)
  5. Add an alias for your script (e.g. alias myscript=my_script.sh)