Bash while 循环中找不到脚本命令错误

Bash script command not found error in while loop

我有问题,但仍然无法处理。 :( 这是我的代码

declare -i disk_usage_rate=$(df -h /appdata/SCT_CDR | cut -d '%' -f 1 | awk 'NR==2{print }')

while ["$disk_usage_rate" -gt 80]
do
...
...
done

我从 df -h 命令获取磁盘使用率。但是在 while 循环中我得到了 followig 错误。顺便说一句,它是 bash 脚本。

bash: [84: command not found

我尝试了很多东西,但我还没有解决。

我看到一个错误:在您的 while 行的 '[' 之后和 ']' 之前添加一个 space :

while [ "$disk_usage_rate" -gt 80 ]

好点了吗?

您在 while 循环中使用的方括号附近缺少 space,如下所示 -

declare -i disk_usage_rate=$(df -h /appdata/SCT_CDR | cut -d '%' -f 1 | awk 'NR==2{print }')

while [ "$disk_usage_rate" -gt 80 ]
do
...
...
done

A bit of history: this is because '[' was historically not a shell-built-in but a separate executable that received the expresson as arguments and returned a result. If you didn't surround the '[' with space, the shell would be searching $PATH for a different filename (and not find it) . – Andrew Medico Jun 24 '09 at 1:13

参考 - bash shell script syntax error