完成的產品旨在以遞歸方式計算指定目錄中的所有內容,或者在沒有輸入參數時輸入當前內容。現在我只是試圖讓它在指定的目錄中計算任何東西。我很難得到最後的陳述來計算任何事情。 它會在目錄中回顯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