Code Movement

Short and Long Options in Scripts

When running programs you sometimes have the option to specify short and long options. For example a program ‘backup_files’ could be called the following ways

With short options

$ backup_files -h "abc" -p "4000"

With long options

$ backup_files --host "abc" --port "4000"

They both do the same thing, but one is easier to read.

Short options are easier to type, and so people tend to type these for commonly used commands.

The key benefit I find with long options is that they are more readable. You only need to type the long option once, but everyone after you will be able to benefit from the time invested. Sometimes it is not apparent what a “-p” might be. But “–port” is very clear, and can save someone valuable time when reading through the code.

Time is precious. Be mindful of when you write a script that others will be calling or reading through, and use long options where it makes sense.