if 语句返回 [[: 未找到

if statement returning [[: not found

我正在编写一个极简的小脚本,我需要检查值。

大小将是一个浮点数,或者带小数点的数字,例如 28.0。

出于某种原因,每当我 运行 时,我都会收到此错误:

   while read -r line;
   do
           sample=$(echo $line | awk 'BEGIN{FS="/"}; {print }')
           size=$(aws s3 ls --summarize --human-readable $line | grep "Total Size:" | awk 'BEGIN{FS=" "}; {print }')
   #       aws s3 cp $line ./crams/
           if [[ $( echo "${size} < 20" | bc ) -eq 1 ]]; then
                   echo "${sample}\t${size}"
           fi
   done < 

download-aws.sh: 6: download-aws.sh: [[: not found 

有什么想法吗???

另外,如果您知道比较浮点数和整数的更好方法...那就太好了!

谢谢

编辑:

所以我找到了解决办法,我把if语句改成了:

if [ $( echo "${size} < 20" | bc ) -eq 1 ]; then

如果有人能指出我对括号背后的逻辑等做出一些很棒的解释的方向......那就太棒了!

来自“Bourne Shell built-ins”文档:

https://www.gnu.org/software/bash/manual/html_node/Bourne-Shell-Builtins.html

test
[
test expr
Evaluate a conditional expression expr and return a status of 0 (true) or 1 (false). Each operator and operand must be a separate

argument. Expressions are composed of the primaries described below in Bash Conditional Expressions. test does not accept any options, nor does it accept and ignore an argument of -- as signifying the end of options.

When the [ form is used, the last argument to the command must be a ].

换句话说,

  • [ 是“测试”的别名

问:您是否有机会为“大小”分配一个整数?因此,也许您的测试条件可以简化为:

if [ $size -lt 20 ]; then
 ...
fi