I have started learning Unix shell scripting using korn shell. Please enlighten me finding the mistake I am doing while writing a ksh code for below a problem as stated below :
My script takes 2 arguments. I have to sum the arguments if they are numbers, else print them as they are. My code is as below:
#!/usr/bin/ksh
arg1=$1
arg2=$2
if echo $arg1 | grep '^[0-9]+$' && echo $arg2 | grep '^[0-9]+$'
then
echo ${expr $arg1 + $arg2}
else
echo $arg1 and $arg2
fi
I have tried this a number of times to get the right output but all in vain. It always executes the else condition. If I run the script :
sh var_regex_match.sh 40 50
the output I get is :
40 and 50
Please pardon me for any mistake in case I made while posting my question. Thanks much for helping!