2) eval " ... entire case structure ..."
3) the literal, not the variable
The first does not work with ksh because it does not have the feature (nor built-in shopt, which is also required), so that leaves the second and third.
The second might require some re-writing, because you need to provide eval with a string of the entire case statement. That would normally be done with double quotes to allow the variable to be expanded. You are already using double quotes, so that would need to be fixed.
In this specific situation, I would use the literal.
There may be features in ksh which allows you to use the variable, but I didn't try anything other than the choices above. Perhaps a ksh expert will stop by with additional advice.
Here I cannot use literal because the values are obtained at runtime and from that the user has to make a choice.
Also I did not understand how to use the second option.
#!/bin/bash -
# @(#) s2 Demonstrate variable in case, eval, extglob (bash).
echo
echo "(Versions displayed with local utility \"version\")"
version >/dev/null 2>&1 && version "=o" $(_eat $0 $1)
set -o nounset
echo
echo " Results:"
x="a|b|c|d"
echo " x is :$x:"
echo " Desiring yes, but getting no:"
case a in
$x) echo yes;;
*) echo no;;
esac
echo
echo " Expecting yes:"
case a in
a|b|c|d) echo yes;;
*) echo no;;
esac
echo
echo " Various features, expecting yes (echo included):"
shopt -s extglob
case a in
@($(echo $x))) echo yes;;
*) echo no;;
esac
echo
echo " Various features, expecting yes (echo omitted):"
shopt -s extglob
case a in
@($x)) echo yes;;
*) echo no;;
esac
echo
echo " With eval:"
eval "case a in
$x) echo yes;;
*) echo no;;
esac "
exit 0
Producing:
% ./s2
(Versions displayed with local utility "version")
Linux 2.6.11-x1
GNU bash 2.05b.0
Results:
x is :a|b|c|d:
Desiring yes, but getting no:
no
Expecting yes:
yes
Various features, expecting yes (echo included):
yes
Various features, expecting yes (echo omitted):
yes
With eval:
yes