bash



  • I'm making a simple bash calculator:

    #!/bin/bash
    

    while [ 1 -eq 1 ]
    do
    read arg1 op arg2
    if [[ "$arg1" -eq "exit" ]]
    then
    break
    fi

    flag=0
    for ops in + - * / % **
    do
        if [[ "$op" = "$ops" ]]
        then
            flag=1
        fi  
    done 
    
    if [[ $flag = 1 ]]
    then
        let "result = $arg1 $op $arg2"
        echo "$result"
    else
        echo "error"
    fi
    

    done

    echo "bye"

    The point is, at the entrance, I'm giving three meanings, arguments and surgery between them. For example, 12 + 5

    Everything's working well except operations. * and **

    What's the matter?



  • for ops in + - * / % **

    at least. * and ** I'd like all the arguments:

    for ops in '+' '-' '*' '/' '%' '**'
    

    Then the shell won't try to to do anything.




Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2