编写脚本,给系统中所有已存在的用户打个招呼,格式参考为 hello penndu and your id is 1000。
参考答案
一题:
1 2 3 4 5 6 7
#!/bin/bash sum=0 for i in `seq 1 100` do sum=$[$i+$sum] done echo$sum
二题:
1 2 3 4 5 6 7 8 9 10 11 12
#!/bin/bash n=0 while [ $n -lt 1 ] do read -p "Please input a number, it must greater than 1: " n done sum=0 for i in `seq 1 $n` do sum=$[$i+$sum] done echo$sum
三题:
1 2 3 4 5 6 7 8
#!/bin/bash cd /root/ for f in `ls` do if [ -d $f ] ; then cd -r $f /tmp/ fi done
四题:
1 2 3 4 5 6
#!/bin/bash groupadd users for i in `seq -w 0 99` do useradd -g users user_$i done
五题:
1 2 3 4 5 6 7 8
#!/bin/bash cd /cjk/ for f in `ls` do if [ -f $f ] ; then mv$f$f.bak fi done
六题:
1 2 3 4 5 6 7
#!/bin/bash for i in `cat /etc/passwd` do username=`echo$i | cut -d : -f 1` id=`echo$i | cut -d : -f 3` echo"hello $username and your id is $id" done
条评论