How can I compare a variable in bash shell script to less than 1?
I did before, but I get ‘1: No such file or directory’
grep_result=`grep -r $ID . | wc -l`
echo $grep_result
# it said '1: No such file or directory'
if [ $grep_result < 1 ]; then
echo "Wrong id.
exit 1
fi
From bash’s perspective this means pipe the file called
1into the $grep_result variable. You need to use the-ltoperator in this case. (le stands for less than)