Parsing command line arguments in Bash
There’re many ways to parse arguments that were passed to a bash script. I’ll show two similar methods to parse the parameter schema -o /foo/
and --output=/foo/
. The second example can also handle commands.
String manipulation just using Bash
If you’re not familiar with manipulation of string (like ${var#=*}
or similar) keep on reading. We’ll select sub-strings from the arguments in the following scripts. The command to do so looks like this: ${<VARIABLE><SPLIT-CHARS><REGEX>}
The split chars define what the result is, which is always one single string. There’re four different ones: (more…)