Hi,
I am calling a script script2.shl from script1.shl as below
script2.shl "TABLE_NAME" -r 10
In that I have to validate the parameter 4.
i.e : it should be only 10 20 30 40 50
I know that I can do it by checking like below
if [[ $4 -eq 10 -o $4 -eq 20 -o $4 -eq 30 -o $4 -eq 40 -o $4 -eq 50 ]]; then
echo "TRUE"
else
echo "FALSE"
fi
But my question here is, can I check all these in a single statement and not like giving "-o" for each value.
case $4 in
[12345]0) echo true;;
*) echo false;;
esac
Use the below if condition.
if [ `sed '/^[1-5]0/!d' <<<$4` ]
then
echo "TRUE"
else
echo "FALSE"
fi
The external command (sed) is slow and unnecessary.
The "here string" (<<<) is not portable.
That test will succeed even if $4 is 1000.