#!/usr/bin/perl
$count=0;
while($count < 100){
print "\n\n\n\n";
print "please input password: \n";
$count+=2;
#print "$count \n";
$ftp=1;
$news=2;
$zhaoyun=3;
$postfix=4;
$oracle=5;
$ntp=6;
$line=<STDIN>;
if($line eq "$ftp\n"){
  print "ftp \n";
  $a=`cat /etc/passwd |grep ftp | sed -n 1p`;
  print $a;}else{
  if($line eq "$news\n"){
     $a=`cat /etc/passwd |grep news | head -n 1`;
     print $a;
    print "news \n";}else{
    if($line eq "$zhaoyun\n"){
     $a=`cat /etc/passwd |grep zhaoyun | head -n 1`;
     print $a;
      print "zhaoyun \n";}else{
      if($line eq "$postfix\n"){
        $a=`cat /etc/passwd |grep postfix | head -n 1`;
        print $a;
        print "postfix \n";}else{
        if($line eq "$oracle\n"){
         $a=`cat /etc/passwd |grep oracle | head -n 1`;
          print $a;
          print "oracle \n";
            }else{
          if($line eq "quit\n"){
            exit;}else{
            if($line eq "$ntp\n"){
              $a=`cat /etc/passwd |grep ntp | head -n 1`;
              print $a;
              print "ntp \n";}else{
              print "password input error! \n";
             }
            }
          }
        }
      }
     }
   } 
  }

实现输入对应的数字,打印相应的内容。

[root@bogon perl]# ./test

please input password:
1
ftp
ftp:x:14:50:FTP User:/var/ftp:/sbin/nologin

please input password:
2
news:x:9:13:news:/etc/news:
news

please input password:
3
zhaoyun:x:500:501::/home/zhaoyun:/bin/bash
zhaoyun

please input password:
fd
password input error!

please input password:
quit
[root@bogon perl]#