I want to check the directory size:
• Low if the directory uses less than 3 MB of disk space
• Medium if the directory uses more than 3 MB and less than 8 MB of disk space
• High if the directory uses equal to or more than 8 MB disk space
For example:
> ./size.sh /usr/bin High > ./size.sh /tmp Low Here is the code that I try even though the folder contains this directory I still cannot do it.
#!/bin/bash dir="breakfast" DIRSIZE=`du -h "$dir"` a=3145728 b=8388608 if (DIRSIZE -le "$a"); then echo "Low" else if (DIRSIZE -gt "$a" && DIRSIZE -lt "$b") echo "Medium" else if (DIRSIZE -ge "$b") echo "High" fi Output:
sh quota.sh : not found: du: cannot access 'breakfast'$'\r': No such file or directory quota.sh: 9: Syntax error: word unexpected (expecting "then")
\rs mean your file is in DOS/Windows format.-gtis an argument to thetestcommand, also called[. It doesn't make sense in another context --(does not runtest.DIRSIZEand expect the variable name to be replaced with a value except in an arithmetic context, and if you were in an arithmetic context then-gtwouldn't be legal syntax, you'd need to use>instead.thenafterelse if