Click to See Complete Forum and Search --> : Simple bash script help.


demonjinn
07-22-2002, 06:15 PM
I'm writing a script to list the files and sizes in a directories, then I want to test the size of the file so if its over 100(example) then I want it to echo. The problem I think is that it's trying to test string, the following is what I have, any improvements, or comments are very welcome. Thanks.

#!/bin/bash

for file in $(dir); do
tmp=`du $file`
size=`echo $tmp | cut -d' ' -f1`
echo $file $size
if ["$size" -gt 100]; then
echo $file is bigger then 100.
fi
done

yours

jinn

cwolf
07-23-2002, 04:33 AM
You have forgotten the whitespaces in the if-statement:
if [ "$size" -gt 100 ]; then ....

demonjinn
07-23-2002, 07:17 AM
Spot on, sometimes I need a smack in the face, thanks.

yours

jinn