I need to loop through a text file provided and count the number of characters in the file. The file will only contain one word that I am supposed to analyze. So basically, I just need to know the length of the word. I want to assign the length to a variable that I have defined in the bash file. Here's what I have(ignore the other if statement at the end, I know that it is working properly. I just need help with the while loop):
#!/bin/bash
FILE=$1
COUNT=0
NUMCHARS=0
while IFS= read -rN1 char; do
if [[ "$char" == $'[a-zA-Z0-9#$+%@]' ]]; then
let NUMCHARS=NUMCHARS+1
fi
done < "$FILE"
if [ -r "${FILE}" ]; then
if /bin/egrep -q [09] $FILE ; then
let COUNT=COUNT+5
fi
fi
echo $COUNT
echo $NUMCHARS
wccommand?