The Script

While researching and learning different tasks to do for my personal scripts, I tried keeping my code examples in different files in a directory. It was very unorganized and a bit overwhelming to deal. Instead I started writing a script that functions as a library for all the things I have learned.

The script keeps everything in one spot and it’s much easier to work on it. It also acts as a functioning style guide for myself so I can standardize my own future scripts. It’s also easy to add code or work on existing code. I usually have it open whenever I am writing something new to use as a quick reference guide.

Some of the features I have worked on include:

  • Making it easier to use POSIX getopts. I can easily add long options. I also made it simple for me to process arguments or deal with conflicting options.
  • Working with simple “arrays” (positional parameters). There’s a nice little function that can save the array to a variable which can then be set again to be used in different parts of the script.
  • a Yes/No confirmation function which can accept a y or n character instantly without pressing enter to proceed.
  • A few of examples extracting data from variables using variable expansions
  • An enter password function that works similar to the read -rscommand
  • A couple examples of using the trap command to help reset changes made during a script

I tried my best to make it easy and obvious to understand. I know future me would get annoyed trying to relearn something I worked on before when I am focused on the script I want to write currently.

I’m learning more about the very basic commands of Linux which is why I prefer writing POSIX portable scripts over Bash scripts. Deconstructing read -rs is a good example. I got to play around with the stty command and learn a couple things about terminal settings.

It’s a nice, simple and ongoing project. Maybe there is something useful in there for anyone else writing POSIX portable scripts. I would like to learn a little about awk and sed in the future but I haven’t found a project yet where that can be used.