CORE/count_characters.sh

37 lines
1 KiB
Bash
Raw Normal View History

#!/bin/bash
function dircount() {
if [ "$VERBOSE" == "true" ]; then echo ":: Checking directory \"$*\"..."; fi
cd "$*" || exit 54
for file in $FILEEXTENSION; do
export "file_full=$*/$file"
if [ -d "$file" ]; then
dircount "$file_full"
elif [ -f "$file" ]; then
if [ "$IGNORE_SCRIPT" == "true" ] && [ "$file" == "count_characters.sh" ]; then
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping this script"; fi
else
if [ "$VERBOSE" == "true" ]; then echo ":: Counting characters in file \"$file_full\"..."; fi
export "COUNT_FILE=$(wc -m < "$file_full")"
export "COUNT=$((COUNT + COUNT_FILE))"
fi
else
if [ "$VERBOSE" == "true" ]; then echo ":: Skipping \"$file_full\" (no file or directory)"; fi
fi
done
cd ..
}
if [ "$FILEEXTENSION" == "" ]; then
export "FILEEXTENSION=*"
fi
if [ "$*" == "" ]; then
dircount "$(pwd)"
else
dircount "$(pwd)/$*"
fi
if [ "$VERBOSE" == "true" ]; then echo ""; fi
if [ "$NUMBER_ONLY" == "true" ]; then
echo "$COUNT"
else
echo "Characters counted: $COUNT"
fi