Trying to create a bash script to check for users with no home directories:
homeless=()
cat /etc/passwd | awk -F: '{ print $1 " " $3 " " $6 }' | while read user uid
dir; do
if [ $uid -ge 1000 -a ! -d "$dir" -a $user != "nfsnobody" ]; then
homeless+=("$user, ")
fi
done
echo ${homeless[@]}
Does anyone know why my array is empty, even though the script produces an output?
If I echo $user in the while loop like this:
if [ $uid -ge 1000 -a ! -d "$dir" -a $user != "nfsnobody" ]; then
echo "$user, "
fi
done
I can achieve an output of:
#./script.sh
testuser1, testuser2,