bash命令;阅读-r";有时失败

bash命令;阅读-r";有时失败,bash,Bash,我有一个小脚本来读取文件系统以检查文件系统中剩余的空间,它有时工作,但由于未知原因失败。当它失败时,它永远不会恢复。我看不出是什么原因使艾利保持不安。如果有人能洞察问题,我将不胜感激 while :; do str="$(df | grep '/var/log' )" if [ $? -ne 0 ]; then echo "Somethin's wrong" fi if [ -z "$str" ]; then ec

我有一个小脚本来读取文件系统以检查文件系统中剩余的空间,它有时工作,但由于未知原因失败。当它失败时,它永远不会恢复。我看不出是什么原因使艾利保持不安。如果有人能洞察问题,我将不胜感激

while :; do
    str="$(df  | grep '/var/log' )"
    if [ $? -ne 0 ]; then
            echo "Somethin's wrong"
    fi
    if [ -z "$str" ]; then
            echo null str
            sleep 1
            continue
    fi
    read -r map size used avail use mount <<< $str
    if [ -z "$avail" ]; then
        echo Iter:$ext: mount: $mount avail:$avail size:$size, use:$use, used:$used
    fi
    if [ $avail -eq 0 ]; then
        echo Iter:$ext: mount: $mount avail:$avail size:$size, use:$use, used:$used
        break
    else
        sleep 1
    fi
done
你测试得对吗

if [ -z "$avail" ]; then
但即使$avail为空,您仍然可以执行

if [ $avail -eq 0 ]; then
这将导致错误消息。把它放进一个盒子里

if [ -z "$avail" ]; then
...
elif [ $avail -eq 0 ]; then
...
fi

您使用的是哪个版本的
bash
?在版本4.3和4.4中修复的字符串中有各种各样的错误,包括未加引号的参数扩展。具体来说,所有字段都存储在
map
中,其余变量未设置
read-r映射大小用于装载
$ext
版本在您发布的两个调试文件中均为空,并导致错误消息
/run.sh:第83行:[:-eq:unary运算符应为
。我没有看到任何像
ext=Something
这样的代码可以设置值。这是打字错误还是错误?;-)。Good luck.ext是在输入此代码之前设置的
if [ -z "$avail" ]; then
...
elif [ $avail -eq 0 ]; then
...
fi