Loops
#!/bin/bash
# example "for" to count directories and files in one route
if [ $# -eq 1]
then
directories=0
files=0
input=$1
for i in $(ls $input)
do
if [ -d $input/$i ]
then
directories=$(($directories + 1))
fi
elif [ -f $input/$i ]
then
files=$(($files + 1))
fi
done
else
echo "Usage: bash for.sh input"
fi
echo "In $input there are $directories directories"
echo "In $input there are $files files"Last updated