#!/bin/bash # userAudit: print invalid usernames #! Safe iteration over /etc/passwd using while read -r awk -F ":" '{print $1}' /etc/passwd | while read -r username; do firstChar="${username:0:1}" badChar=false # Check if username contains only letters for ((i=0; i<${#username}; i++)); do char="${username:i:1}" if ! [[ "$char" =~ [A-Za-z] ]]; then badChar=true break fi done # Flag invalid usernames #! Corrected logic to properly flag invalid usernames: #! check if the firstchar is NOT a letter if (( ${#username} > 20 )) || ! [[ "$firstChar" =~ [A-Za-z] ]] || $badChar ; then #! Quotes around $username in echo for robustness. echo "$username" fi done