[::整数表达式预期bash脚本

时间:2015-09-24 15:28:08

标签: linux bash ubuntu

我不断得到[:-ge:一元运算符的预期和[:-gt:一元运算符的预期。不知道这笔交易是什么。我已经尝试将变量放在引号中然后我得到[::整数表达式。这是我的剧本:

    #!/bin/bash
read -p "How big is the compressed file size in bytes?: "$file_size;

if [ $file_size" -lt 5000 ]
then
    echo "The compression ratio is 90%"

elif [ $file_size -ge 5000 ] && [ "$file_size" -le 50000 ]
then
    echo "The compression ratio is 70%"

elif [ $file_size -gt 50000 ]
then
    echo "The compresison ratio is 40%"
fi

1 个答案:

答案 0 :(得分:3)

这一行

read -p "How big is the compressed file size in bytes?: "$file_size;

有多个问题。首先,在-p参数和变量" name"之间需要一个空格。 (稍等一点):

read -p "How big is the compressed file size in bytes?: " $file_size;

其次,名称不应以$为前缀(除非file_size包含要设置的变量名称)。

read -p "How big is the compressed file size in bytes?: " file_size

如上所述,您的read语句未设置名称,因此默认为$REPLY。这意味着file_size没有价值。

相关问题