i have the following script:
#!/bin/bash for ((i=1; i<=$#; i++)); do if [ ! -d $i ] then echo $i its not a directory >> file.txt else DIRECTORY=$(ls -l $i | grep ^d | wc -l) LINK=$(find $i -type l | wc -l) FILE=$(ls -A $i | wc -l) echo `date "+%H:%M:%S %d-%m-%y"` directory $i file count: $FILE link count: $LINK subdirectory count: $DIRECTORY >> file.txt fi done
this script count the subdirectories, links and files from a directory entered by parameter(it can be more than 1).
i am struggling with the loop, it returns "echo $i its not a directory" reading $i as 1 instead of $1, i do understand why it does that but i am starting with scripts and don't know how to fix this. i think a "while" can be a substitute for that "for" but don't know how to use it properly.
thanks for the help!