Bash conditional statement -


i realize simple problem, can't figure out why isn't working. i'm attempting check if folder larger 35gb , if so, remove files older 3 days in it.

with code:

#!/bin/bash max=35000000000 if [ $(du -sb ~/mega | cut -f1) \> $max ]    find ~/mega/* -mtime +3 -exec rm -fr {} \; fi 

i'm getting following errors:

 syntax error near unexpected token `fi' 

you missing semicolon or line jump before then keyword. beware bash uses > compare strings, not numbers. numeric comparison should using either -gt or bash specific (( arithmetic expression evaluator. instance:

#!/bin/bash max=35000000000 if (( $(du -sb ~/mega | cut -f1) > $max ))    find ~/mega/* -mtime +3 -exec rm -fr {} \; fi 

reference: bash conditional constructs


Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -