I haven't been able to find anything related to this nor can my professor explain what's going on. Below is the problem description:
After quite a bit of debugging following is the bash script to print odd
or even
:
echo $1
odd_even=$(echo "$1 % 2" | bc -l)
echo $odd_even
if [[ $odd_even -eq 0 ]]
then
echo "even"
else
echo "odd"
fi
Following is the output:
$ bash logic_ex2.sh 3
3
0
even
This is weird because the variable odd_even
contains 0
while the argument is 3
.
We ran the following command to check whats wrong with the echo "3 % 2" | bc -l
construction since without using that construction we could get the script working:
$ echo "3 % 2" | bc -l
0
Then we ran bc
in the terminal and ran 3 % 2
which gave 1
as the proper output.
Can somebody please explain what is happening here?