I was trying to make a calculator in bash and everything except multiplication works.
My script turns “*” into 0 when I try to multiply.
There is the code:
#!/bin/bash
calculator(){
if [ $3 = "+" ] ; then
echo [ $1 $3 $2 ]
else
if [ $3 = "-" ] ; then
echo [ $1 $3 $2 ]
else
if [ $3 = "/" ] ; then
echo [ $1 $3 $2 ]
else
if [ $3 = "*" ] ; then
echo [ $1 $3 $2 ]
else
echo "$3 error"
fi
fi
fi
fi
}
calculator 1 2 *
New contributor
IronPerrot is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
6