display_account.sh
#!/bin/bash
echo "方式一:"
awk -F: '{print $1}' /etc/passwd
echo "方式二:"
cut -d: -f1 /etc/passwd
echo "方式三:"
sed 's/:.*//' /etc/passwd
验证:
[root@logstash ~]# sh display_account.sh
方式一:
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
systemd-network
dbus
polkitd
sshd
postfix
ntp
nginx
tcpdump
apache
mysql
方式二:
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
systemd-network
dbus
polkitd
sshd
postfix
ntp
nginx
tcpdump
apache
mysql
方式三:
root
bin
daemon
adm
lp
sync
shutdown
halt
mail
operator
games
ftp
nobody
systemd-network
dbus
polkitd
sshd
postfix
ntp
nginx
tcpdump
apache
mysql
[root@logstash ~]#