How to use shell var for pattern string at KSH

Hi there, In the following test, how to use shell var for pattern, regular expression. I need to accept pattern at argument, use it to pattern matching at shell script.

Test:

#!/bin/ksh
# name t.sh
exp="a@(a|b)"
touch aa ab ac
echo "\nTest without variable"
echo "---------------------"
ls -1 a@(a|b)
echo "\nTest with with variable(exp=$exp)"
echo "----------------------"
ls -1 $exp
######################################
# test 
######################################
# chmod 775 t.sh
# t.sh 
######################################
# test output
######################################
# Test without variable
# ---------------------
# aa
# ab
#
# Test with with variable(exp=a@(a|b))
# ----------------------
# a@(a|b) not found     # <-- probelm
######################################
ksh-M 93t 2008-11-04$ ./t.sh 

Test without variable
---------------------
aa  ab

Test with with variable (exp=a@(a|b))
----------------------
aa  ab
ksh-M 93t 2008-11-04$ cat t.sh 
#!/bin/ksh
# name t.sh
exp='a@(a|b)'
touch a{abc}
print -- "\nTest without variable"
print -- ---------------------
ls a@(a|b)
print -- "\nTest with with variable (exp=$exp)"
print -- ----------------------
eval ls $exp

eval ls ${exp} may be more efficient than using a new child sh,
such as ksh -c "ls $exp".

Radoulov, Much thanks for your help. :slight_smile: