[SOLVED] set variable for the output
by prayag_pjs from LinuxQuestions.org on (#5NFKQ)
I have below output -
Code:[root@server]# cat /etc/passwd | awk -F ":" '{print $1}'
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
systemd-bus-proxy
systemd-network
dbus
polkitd
tss
sshd
postfix
chrony
automatehub
mysql
prometheus
[root@server]#
Now I want to assign above output to variable via for loop something like this
Code:var1=root
var2=bin
.
.
.
varn=outpuntnI can think of only this solutions -
Code:[root@server]# for i in `cat /etc/passwd | awk -F ":" '{print $1}'` ; do var1=$i ;done
[root@server]# echo $var1
prometheus
[root@server]#But it gives only one variable. How to achieve this for multiple variables. Can someone can guide on how to achieve this?


Code:[root@server]# cat /etc/passwd | awk -F ":" '{print $1}'
root
bin
daemon
adm
lp
sync
shutdown
halt
operator
games
ftp
nobody
systemd-bus-proxy
systemd-network
dbus
polkitd
tss
sshd
postfix
chrony
automatehub
mysql
prometheus
[root@server]#
Now I want to assign above output to variable via for loop something like this
Code:var1=root
var2=bin
.
.
.
varn=outpuntnI can think of only this solutions -
Code:[root@server]# for i in `cat /etc/passwd | awk -F ":" '{print $1}'` ; do var1=$i ;done
[root@server]# echo $var1
prometheus
[root@server]#But it gives only one variable. How to achieve this for multiple variables. Can someone can guide on how to achieve this?