I'm trying to learn basic scripting in Unix/Linux OS. Task I have right now is to make a basic calculator. Format is:
calc <number> <operand> <number>
#!/bin/bash -u
PATH=/bin:/usr/bin ; export PATH
umask 022
echo -n "$1$2$3="
case "$2" in
'+' ) echo `expr $1 "+" $3` ;;
'-' ) echo `expr $1 "-" $3` ;;
'*' ) echo `expr $1 "*" $3` ;;
'/' ) echo `expr $1 "/" $3` ;;
* ) echo 'unknow operation' ;; # the "default" if nothing else matches
esac
what happens is, when user type '*' it replaces it with glob pattern. I cant use any quotation marks to prevent it
" doesn't prevent it from happening
' displays screen this
$1$2$3=
is there a way to keep variables with $ while preventing * from messing up the application?
What I want is when user types "calc 2 * 3" computer to return following
2*3=6