Elegant way to pass arguments to a bash script

When I started to write bash scripts, I found that it was really convenient to use the basic way to pass arguments with $1 $2 and so on.

It’s quick and easy to write, but not very flexible because the argument order maters and you need to write a check condition.

When I discovered the getopts option, it made my scripts way better. In the following example, I added a function named “commands” that executes the command if the dry-run flag is not set and just display the command if not

Another interesting arg is the “set -x” command, that prints all the command executed by the script.

Continue reading “Elegant way to pass arguments to a bash script”