如何将 bash shell 脚本中的变量与小于 1 的变量进行比较?
我以前做过,但我得到“1:没有这样的文件或目录”
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
最佳答案
从 bash 的角度来看,这意味着将名为 1
的文件通过管道传输到 $grep_result 变量中。在这种情况下,您需要使用 -lt
运算符。 (le 代表小于)
grep_result=`grep -r $ID . | wc -l`
echo $grep_result
# it said '1: No such file or directory'
if [ $grep_result -lt 1 ]; then
echo "Wrong id.
exit 1
fi
关于bash - 如何修复 '1: No such file or directory',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13500337/