I want to read a file and inside the file have number words. I have to do operation math. but I dont know why my script doesn't work.

Exemple : seven one minus six one

the answer in the terminal :

$ 10

sorry for my script I start to learn how to script ..


a=( ["zero"]="0" ["one"]="1" ["two"]="2" ["three"]="3" ["four"]="4"
    ["five"]="5" ["six"]="6" ["seven"]="7" ["eigth"]="8" ["nine"]="9" ["plus"]="+" ["minus"]="-" ["time"]="*" ["divide"]="/" ["modulo"]="%" )

if [ $# -eq 0 ]; then
    echo " Error : missing a file"
    exit 1
    if [ ! -f "$1" ]; then
            printf 'Error:file'" "$1" ""dont exist\n'" >&2
            exit 2

while read line 
    for word in $line
            case $ in
                            echo $(( $a + $a ))
                            echo $(( $a *$a ))

$ cat file

nine six one plus one two

$ 973

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.