2 ms·
Now do that again, but this time the regular expression is controlled by 2 command line params, one which gives it the substitution, the other one is a boolean
by usrbinbash 4y ago
Now do that again, but this time the regular expression is controlled by 2 command line params, one which gives it the substitution, the other one is a boolean switch that tells it whether to ignore case. And the script has to give a good error if the substitution isn't a valid regular expression. It should also give me a helptext for its command line options if I ask it with `-h, --h`.
In python I can use `opt/argparse`, and use the error output from `re.compile` to do this.
Of course this is also possible in bash, but how easy is it to code in comparison, and how maintainable is the result?
- lbhdc 4y agoIn the example I gave I wouldn't write that in a script file, so I would just alter the command itself. If I wanted to parse cli args I would use case on the input to mux out the args. I personally prefer writing cli interfaces this way (when using a scripting language). while test $# -gt 0; do case "$1" in -f|--flag) shift; FLAG="$1";; esac shift done
- scbrg 4y agoMan, you chose the wrong username, didn't you? ;-)
- usrbinbash 4y agoNot really, I love bash. I also love perl and vimscript btw. :D