练习一:写一个脚本 1.设定变量FILE的值为/etc/passwd 2.依次向/etc/passwd中的每个用户问好,并且说出对方的ID是什么 形如:(提示:LINE=`wc -l /etc/passwd | cut -d" " -f1`) Hello,root,your UID is 0. 3.统计一个有多少个用户 程序如下: #!/bin/bash file="/etc/passwd" line=` wc -l $file|cut -d" " -f1 ` for i in ` seq 1 $line `;do userid=` head -$i $file| tail -1 |awk -F ":" ‘{print $3}‘` username=` head -$i $file| tail -1 |awk -F ":" ‘{print $1}‘` echo "hello,$username!your uid is $userid" done echo "There are $line users"
时间: 2024-10-17 09:19:53