guyuehhh 发表于 2018-8-22 12:10:19

shell练习题1-linux运维

练习一:写一个脚本  
       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"


页: [1]
查看完整版本: shell练习题1-linux运维