Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bash script command not found error in while loop [duplicate]

I have problem and cant still handle with it. :( Here is my code

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

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

I get the disk usage rate from df -h command. But in while loop I get the followig error. Btw it is bash script.

bash: [84: command not found

I tried so many things but I didnt solve yet.

like image 340
Süleyman Orhan Avatar asked Aug 10 '26 23:08

Süleyman Orhan


1 Answers

You are missing space near square brackets used in while loop such as below -

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

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

Ref - bash shell script syntax error

like image 161
vivekyad4v Avatar answered Aug 12 '26 17:08

vivekyad4v



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!