我在 unix shell 脚本中遇到了一个问题。让我用一个非常简单的例子问你。
假设,我正在获取用户输入并比较两个数字。
echo "Enter the first number"
read a
echo "Enter the second number"
read b
if [ a -gt b ]---------------------->I have not used $ before variable name.
then
echo "a is greater"
else
echo "b is greater"
fi
在这个例子中,我应该使用 $ 来获取变量的值。一不小心,我忘记了。不过,它给了我正确的结果,如何以及为什么?
我尝试使用 sh -x 文件名进行调试。但是,它在比较时没有显示任何值(因为我没有使用 $ 符号)。
shell如何决定哪个更大,反之亦然?它在内部如何运作?
谢谢。