Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Case statement with ";|" [not implemented]



Hello all :)

I'm new to the mailing list.

I'm trying to convert the (simplified) code below to a case statement structure:
===
  if [[ $mycase -eq 0 ]]; then
      echo "mycase is 0"
  else
      if [[ $mycase -eq 1 ]]; then
          echo "mycase is 1"
      else
          echo "mycase is 2"
      fi
      echo "mycase is 1 or 2"
  fi
===

And this is what I got:
===
  case $mycase in
      0)
          echo "mycase is 0"
          ;;
 
      1)
          echo "mycase is 1"
          ;;
 
      2)
          echo "mycase is 2"
  esac
  if [[ $mycase -gt 0 ]] echo "mycase is 1 or 2"
===

My question is, shouldn't there be a way to do this:
===
  case $mycase in
      0)
          echo "mycase is 0"
          ;;
 
      1)
          echo "mycase is 1"
          ;|
 
      2)
          echo "mycase is 2"
          ;|
 
      *)
          echo "mycase is 1 or 2"
  esac
===

Note that ";|" provides an OR-like separator (as opposed to the AND-like ";&" separator) that goes through the case statements. However, unlike ";&", it checks $mycase against 1) and 2) instead of blindly executing case statements 1 & 2.

Wouldn't this be a good addition to ZSH? It certainly seems more useful than ";&".
--
Gerald Lai


Messages sorted by: Reverse Date, Date, Thread, Author