Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/shell/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
shell脚本中的比较_Shell_Unix_Comparison_Sh_Comparison Operators - Fatal编程技术网

shell脚本中的比较

shell脚本中的比较,shell,unix,comparison,sh,comparison-operators,Shell,Unix,Comparison,Sh,Comparison Operators,我正在用shell脚本进行比较 if [ $# -lt 10 ] then echo "PROCEED" else echo "STOP" 我以./test.sh1 2 3 4 5 6 7 8 9 10 11的形式运行脚本 然后输出为“停止” 如果我使用“则需要使用“ 这里也有这样的说法-> 尖括号通常用于命令重定向 如果您要比较整数,请使用-lt表示

我正在用shell脚本进行比较

              if [ $# -lt 10  ]
              then
              echo "PROCEED"
              else 
              echo "STOP"
我以./test.sh1 2 3 4 5 6 7 8 9 10 11的形式运行脚本 然后输出为“停止”
如果我使用“则需要使用“<”而不是-lt”来比较数字,因为-lt进行字符串比较。

如所示:

字符串比较


请注意,Bash使用buildin“test”实现,man test->

这里也有这样的说法->

尖括号通常用于命令重定向


如果您要比较整数,请使用-lt表示小于。

如果我使用“如果我使用If[“$a”\<“$b”],则应该按照您的建议进行操作。不,它只适用于字符串比较。它可能会得到很好的输出,但只是基于ASCII。我的意思是,你必须使用
lt
。我使用“(”括号而不是“[”这个词。如果($#<10))和problem solvedGreat!我将更新我的帖子,反映这一点,因为我提供的链接中总是指出这一点。
              if [ $# < 10  ]
              then
              echo "PROCEED"
              else 
              echo "STOP"