0
while:; do 

read -p "please select your maths operator" choosenOperator 

if [$choosenOperator == *]; then 
break

So hopefully its a little clear what I'm trying to say here. Is there some way of working this so that Bash will take a user input of *, and store that in choosenOperator as the multiplication sign? It works for plus, minus etc but not for multiplication.

Gordon Davisson
  • 118,432
  • 16
  • 123
  • 151
Ciaran
  • 23
  • 6
  • 1
    Double-quote both the variable reference and the literal `*` to keep them from being expanded as filename wildcards (and use a single `=` in a `[ ]` test expression): `if [ "$choosenOperator" = "*" ]`. [shellcheck.net](https://www.shellcheck.net) will point out many of these common mistakes. – Gordon Davisson Apr 11 '21 at 17:39
  • Accepting parameters on the command line is usually a convenient and helpful design, but for this particular use case, probably read the expressions from standard input instead. The `expr` command already exists for evaluation of arithmetic expressions an the command line, anyway (though modern Bash scripts should use the shell's built-in arithmetic expression facility instead). – tripleee Apr 11 '21 at 17:51
  • 1
    @GordonDavisson Thanks very much for engaging with me man. That worked perfectly. I had to go through all the various different if statements and rewrite them in that fashion and then it worked perfectly. Thanks again. – Ciaran Apr 11 '21 at 18:22

0 Answers0