I have a BASH script to add two numbers where I want to pass two numbers via command line arguments.
cat add.sh
a=$1
echo "exit status for a " $?
b=$2
echo "exit status for b " $?
sum=`expr $a + $b`
echo "exit status for sum " $?
echo "result is " $sum
echo "exit status for result " $?
When I run the above script without providing any value or arguments, I am getting following output.
$ ./add.sh
exit status for a 0 (expecting 1 here)
exit status for b 0 (expecting 1 here)
expr: syntax error
exit status for sum 2
result is
exit status for result 0 (expecting 1 here)
I am expecting value of $? as 1 when I am not providing any arguments via command line, so it must be an error for assigning value of a and b.
Can anyone explain why a=$1 or b=$2 doesn't return exit status 1 when NO value is supplied via command line? Why it returns 0 ?