Re: what matched in a case statement

2008-05-14 Thread jidanni
Poor Yorick wrote:
> Is there any way to get a handle on what matched in a case
> statement?  Something like this:
> 
> case "lawlesspoets" in
> *poets)
> echo $CASEMATCH one
Well, nobody would do
> case "lawlesspoets" in
in reality you would always have some variable. So just do
CASEMATCH=lawlesspoets; case $CASEMATCH in ...
so there.




Re: what matched in a case statement

2008-05-14 Thread Bob Proulx
Poor Yorick wrote:
> Is there any way to get a handle on what matched in a case
> statement?  Something like this:
> 
> case "lawlesspoets" in
> *poets)
> echo $CASEMATCH one
> ;;
> lawless*)
> echo $CASEMATCH two
> ;;
> esac

Perhaps matching again?

  foo="lawlesspoets"
  case $foo in
*poets)
  echo ${foo/*poets/one}
  echo ${foo%poets} one
  ;;
lawless*)
  echo ${foo/lawless*/two}
  echo ${foo#lawless} two
  ;;
  esac

Bob