gpt4 book ai didi

linux - [: : integer expression expected bash script

转载 作者:太空宇宙 更新时间:2023-11-04 05:38:37 27 4
gpt4 key购买 nike

我不断收到 [: -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

最佳答案

这一行

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 没有值。

关于linux - [: : integer expression expected bash script,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32765290/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com