Hello. I'd like to change the value of an array and would appreciate any help.
I got an array like this:
users=(root isometric akau)
(This is actually a list of current users) that I'd like to be able to test if the user exists and if they do not, then to remove the person from the array. I've tried experiment with this by putting it in a for loop and evaluating it:
for i in ${users[@]}; do
eval "users=($([ -z $(grep \"^\$i\" /etc/shadow) ] && sed \"s/\$i//g\"))"
done
echo $users
I thought about playing with this some more but I thought I might be getting too complicated (I'm not sure I can put a command in an array). Anyone have an idea on how to do this?
Edit:
How I entered the array variable unset number:
cnt=0
for i in ${users[@]}; do
[ -z "$(grep "^$i" /etc/shadow)" ] && unset users[cnt] || ((cnt++))
done
Edit2:
Actually Dennis's is even better.