hi!
When I have a variable that contains the day let's say Sun06
and i want to check if my variable starts with any letter what pattern should I use?
I tried that one,but it returns syntax error..
if [ "$day" = ([A-Za-z]*) ]; then
hi!
When I have a variable that contains the day let's say Sun06
and i want to check if my variable starts with any letter what pattern should I use?
I tried that one,but it returns syntax error..
if [ "$day" = ([A-Za-z]*) ]; then
I would use case instead of if :
case "$day" in
([A-Za-z]*) echo ok ;;
(*) echo ko ;;
esac
I would also have a preference for case since it is more portable. Since you are using bash you could also use:
if [[ "$day" == [A-Za-z]* ]]; then
--
@jlliagre: in light of our other interesting thread, the double quotes can be left out around the variable in the case statement ( case $day in )
it can also be left out the left hand side in bash's [[ ![]()
[[ $day = [[:alpha:]]* ]]
Ow, yes of course
Thanks neutronscott..