Hey Users,
This simple shell scripts looks through all the sub folders in the given directory and in each sub folder is 2 text files, it counts how many lines are in each file and how many directories where accessed but it reports back all zeros (0)?
Code:
#!/bin/sh
f=0
d=0
u=0
t=0
x=0
find /path/to/my/folder -maxdepth 1 -type d | while read FOLDER; do
f=`expr $f + 1`
if [ -f $FOLDER/domains ]; then
x=`wc -l $FOLDER/textfile1 | awk '{print $1}'`
d=`expr $d + $x`
fi
if [ -f $FOLDER/urls ]; then
x=`wc -l $FOLDER/textfile2 | awk '{print $1}'`
u=`expr $u + $x`
fi
done
t=`expr $d + $u`
echo "Number of folders: $f"
echo "Number of lines in textfile1: $d"
echo "Number of lines in textfile2: $u"
echo "Total number of lines for both text files: $t"
echo "$x"
When i run this test script it get the following output:
Code:
[hades@hades ~]$ sh tester
Number of folders: 0
Number of lines in textfile1: 0
Number of lines in textfile2: 0
Total number of lines in both text files: 0
0
[hades@hades ~]$
I am confused, it lookes ok to me but I'm not very good at these things?