How do I run the script:
./script.sh 1 \* 2
./script.sh 1 '*' 2
How does my script look like:
args="$@" # the first line of the script result=$(($args)) echo "$args = $result"
Does it work: yes
What I want to achieve: I want to use
expr instead of
args="$@" # the first line of the script result=`expr $args` echo "$args = $result"
It works fine for input arguments like
1 + 2, but it does not work properly (or, more likely, at all:
expr: syntax error) for asterisk (star) symbol. I'd like to know why this does not work as desired and how should I fix this.
Script like this:
expr "$@" does work - I just do not understand what is going on when I assign
$@ to a variable.