Tuesday, May 12, 2009

[Shell script] 讓/etc/passwd更利於閱讀

#!/bin/bash
IFS=:
echo "System User list:"
echo "-------------------------------------"
while read username shapass uid gid comm home shell
do
echo "UserName:$username"
echo " 1.password:$shapass"
echo " 2.uid:$uid"
echo " 3.gid:$gid"
echo " 4.comment:$comm"
echo " 5.home:$home"
echo " 6.default shell:$shell"
echo "------------------------------------"
done < /etc/passwd

參考Linux-101 Hacks, hack 88. Read data file fields inside a shell script

No comments: