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" ;;

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?

>Solution :

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

Leave a ReplyCancel reply