my main intense is to to extract only user name from the/etc/passwd
file and store then in array list i can display them one by one for this i have created simple script as below
#!/bin/bash
cat "/etc/passwd" > OUTPUT
echo -e $OUTPUT
IFS=:
read -ra ADDR <<< "$OUTPUT"
for i in "${ADDR[@]}"; do
echo -e $i
done
And the output of
> cat /etc/passwd
root:$1$L15vXdMd$SVx9qKAzHtLcqGN8n2SIc.:0:0:root:/:/bin/sh
sshd:x:74:74:Privilege-separated SSH:/var/empty/sshd:/bin/false
super:x:1111:1100:Ldap user:/opt/www/usr/super:/bin/sh
admin:x:1107:1100:Ldap user:/opt/www/usr/admin:/opt/www/jv/bin/cliInit.sh
guest:x:1101:1100:Ldap user:/opt/www/usr/guest:/opt/www/jv/bin/cliInit.sh
postgres:x:1000:1000:Linux User,,,:/home/postgres:/bin/sh
albert:x:1114:1100:Ldap user:/opt/wwwl/usr/albert:/opt/www/jv/bin/cliInit.sh
ritesh112:x:1125:1001:RADIUS user:/opt/www/usr/ritesh112:/opt/dell/mc/bin/cliInit.sh
might be i am doing wrong way(that's why i ask the question) in above script.As per my logic first redirect the /etc/passwd
to any variable by (cat "/etc/passwd" > OUTPUT
don't know it right or wrong Also as alternative have tried read -ra ADDR <<< "cat /etc/passwd"
but not working ) then separate the output by IFS=:
bash variable and store all username in array ADDR
.
i expect the output of script as follow except sshd
and postgres
user names.
root
super
admin
guest
albert
ritesh112
But it not working any one have idea?