Bash script command not found error in while loop

11,253

Solution 1

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

Solution 2

I see one error : add a space after '[' and before ']' on your while line :

while [ "$disk_usage_rate" -gt 80 ]

Is it better ?

Share:
11,253
Süleyman Orhan
Author by

Süleyman Orhan

Updated on June 04, 2022

Comments

  • Süleyman Orhan
    Süleyman Orhan over 1 year

    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.

  • Süleyman Orhan
    Süleyman Orhan almost 6 years
    thank you very very much i tried to solve it about 1 day. the actually reason should be adhd :( :( thank you a lot. @vivekyad4v
  • Süleyman Orhan
    Süleyman Orhan almost 6 years
    thank you a lot it was the solve :) :) :)
  • vivekyad4v
    vivekyad4v almost 6 years
    no problem :) . Just a heads up - If you are satisfied with the answer always upvote it & mark it as correct. This helps us moving :)
  • chepner
    chepner almost 6 years
    Whether or not [ is a built-in or external command, it's still a command, not part of the if statement or otherwise special syntax.