Search code examples
unixshglob

shell glob pattern trouble


I'm trying to print out an out the corresponds to an input. The input would be a number and the output would print out the number in english. I am having trouble with the syntax/regular expressions in unix. If I were to run this with an input of 277, there would only be "one-hundred" as output. Where it should be "one-hundred twenty." Is there something wrong with it..? I've looked everywhere and it seems right.

I know it's not complete yet but it is bothering me. Any tips?

case "$1" in
1[0-9][0-9]) # 100's
    echo one-hundred
    if [ "$1" == 12[0-9] ]
    then
        echo twenty
    fi
;;

Solution

  • The regex syntax is =~ not == so your if needs to be [[ "$1" =~ 12[0-9] ]] though not every shell supports that syntax