Posts

Showing posts from March, 2019

Parsing bash arguments

If you've ever programmed in bash, then you know that command line arguments are accessed numerically with $1 being the first argument, $2 the second, and so on.For years I've written scripts and just accessed the arguments by their position. This means that if I want to skip an argument, I have to pass an empty string. It also means I must not mix up the order of the arguments I pass! I can finally put those days behind me if I so choose and use switches! A search online, reveals that the question of how to do this is not new and has been answered many times over , but I wanted to abstract the argument parsing code and get it out of my scripts. As I got my first version working, I found that someone else had already done this , but even that code didn't work exactly like I wanted mine too, so I kept working because there's one key bit that everyone seems to ignore. We should be able to use switches with the functions contained in our scripts too! My Goals  I wan