is it possible to call a variable in a case statement, for example
lsmonth=Jan|Feb
l |while read ans
do
mymonth=`echo $ans |awk '{print $6}'`
case $mymonth in
$lsmonth) echo do something
;;
*) echo do something else
;;
esac
done
but doesn't that defeat the purpose of using a variable as valid 'choice'?
Is there a way to do it the way the OPed wanted originally?
I remember seeing something very similar done somewhere...
lsmonth1=Jan; lsmonth2=Feb
l |while read ans
do
mymonth=`echo $ans |awk '{print $6}'`
case $mymonth in
$lsmonth1|$lsmonth2) echo do something
;;
*) echo do something else
;;
esac
done
ls -l |
while read perms links owner group size month day time file x link
do
case $month in
$lsmonth1|$lsmonth2) echo do something
;;
*) echo do something else
;;
esac
done
I know, I wanted to make as few modifications to the OP's script as possible to better illustrate the use of the variables.. Good point though of course...