Skip to content
Advertisement

[: missing `]’ error in Unix | shell Script [closed]

I got a [: missing `]’ error in shell Script

memuse=$ free -m                                                                      
if [ $memuse >80]
then                                                               
echo "Attention: memory utilisation is high on $(hostname) at $(date)" 

This is my code and i got the error like

[tono@webminal.org ~]$sh ./memory_alert.sh                                   
              total        used        free      shared  buff/cache   available       
Mem:          14522        2128        4004        1845        8389       10096       
Swap:             0           0           0                                           
./memory_alert.sh: line 2: [: missing `]' 

Advertisement

Answer

I got the solution

memuse=$ free -m                                                                      
if [ $memuse > 80 ];                                                                  
then                                                                                 
echo "Attention: memory utilisation is high on $(hostname) at $(date)"               
else                                                                                  
echo "Attention : memory utilisation is normal on $(hostname) at $(date)"             
fi 

This is my first time doing bash scripting. So the issue majorly due to the Indentation.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement