Готовый продукт предназначен для рекурсивного подсчета всего в указанной директории или текущего, если аргументы не введены. Прямо сейчас я просто пытаюсь заставить его считать что-либо в указанных каталогах. Мне трудно получить последние заявления, чтобы считать что-нибудь вообще. Он будет отображать 0 файлов в каталоге.Подсчет всех пластов/каталогов в указанном каталоге - скрипты bash/shell
Может ли кто-нибудь дать мне какие-либо советы? Я все еще новичок, так что успокойся, спасибо!
#!/bin/bash
#A shell script program that counts recursively how many directories/files exist in a given directory.
declare -i COUNT=0
declare -i COUNT2=0
#The script will treat COUNT as an integer that is 0 until modified.
if [ "$#" -eq "0" ]
then
for i in *
do
((COUNT++))
done
((COUNT--)) #This is done because there is always an overcount of 1.
echo "There are $COUNT files and/or directories in the current directory here."
fi
if [[ -d $1 ]]
then
for i in $1
do
((COUNT++))
done
((COUNT--)) #This is done because there is always an overcount of 1.
echo "There are $COUNT files and/or directories in $1."
fi
if [[ -d $2 ]]
then
for i in $2
do
((COUNT2++))
done
((COUNT2--)) #This is done because there is always an overcount of 1.
echo "There are $COUNT2 files and/or directories in $2."
fi
exit 0
Где вы обрабатываете рекурсию в своем коде? Вы проверили это? – Derlin