Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Modified default for bash case statement

I have seen the general case statement in bash that an asterisk * to denotes the default pattern. If an expression isn’t matched with any of the other patterns in the case statement the default clause is executed.

case $1 in
  ("-u2") printf "%s\n" "TODO" ;;
  ("-u3") printf "%s\n" "TODO" ;;
  ("-u1"|"-u"|*) printf "%s\n" "$KCFRONT_A" ;;
esac

I have modified it such that the default also gets called for case of -u1 and -u. This strategy seems to work. Is this a valid and understandable thing to do?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

It works, but it’s not necessary. * matches any string, so naming them doesn’t do anything.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading