Quote:
Originally Posted by tostay2003
Hi
I have a variable which should be any number between 1 and 50.
It could also be any string/empty string.
I have a code written below. The point is when the variable contains string.
I don't want the code below to error out. Instead fall in the else bucket.
|
You don't have an "else bucket"; dothis_2 will be executed if either the numerical test or dothis_1 fails.
Quote:
Code:
[ $var -lt 1 -o $var -gt 50 ] && dothis_1 || dothis_2
|
Code:
if case $var in
*[!0-9]* | "" ) false ;;
*) true ;;
esac && [ $var -ge 1 ] && [ $var -le 50 ]
then
echo dothis_1
else
echo dothis_2
fi