Skip to content

Latest commit

 

History

History
20 lines (16 loc) · 473 Bytes

73.md

File metadata and controls

20 lines (16 loc) · 473 Bytes

题目要求

写一个脚本,依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么,如:

Hello, root,your UID is 0.

参考答案

#!/bin/bash
#这个脚本用来问候用户
#作者:猿课-阿铭 www.apelearn.com
#日期:2018-12-11

cat /etc/passwd |while read line
do
    username=`echo $line|awk -F ':' '{print $1}'`
    uid=`echo $line|awk -F ':' '{print $3}'`
    echo "Hello, $username, your uid is $uid."
done