我想写一个关于windows开机输入密码的脚本

回复 收藏
脚本的需求如windows输入密码一样
1、输入正确就直接进去
2、输入失败显示密码错误,请再次输入
我写了半天没写出来~~求高人!!!!
2011-08-13 17:53 举报
已邀请:
0

阿铭 管理员

赞同来自:

  1. #! /bin/bash

  2. ## Writen by Aming!
  3. ## Judging for a word if is your password.

  4. pass="nihao123"
  5. while :; do
  6.     read -p "Please input the password:" word
  7.     if [ $word != $pass ]; then
  8.         echo "The password is wrong, retry."
  9.     else
  10.         exit
  11.     fi

  12. done
0

split_two

赞同来自:

铭哥,我想问一下这个脚本运行后,我输错密码10几次的时候会报一个mima.sh: line 6: [: !=: unary operator expected错误,直接弹出,这个是为什么呢?
0

loveyouhyf

赞同来自:

[root@bogon sbin]# sh password.sh
Please input the password:adf
The password is wrong, retry.
Please input the password:adf
The password is wrong, retry.
Please input the password:adf
The password is wrong, retry.
Please input the password:adfg
The password is wrong, retry.
Please input the password:adfasdf
The password is wrong, retry.
Please input the password:adfgadfa
The password is wrong, retry.
Please input the password:adfadf
The password is wrong, retry.
Please input the password:adfadf
The password is wrong, retry.
Please input the password:adfadf
The password is wrong, retry.
Please input the password:sdew
The password is wrong, retry.
Please input the password:234
The password is wrong, retry.
Please input the password:34454
The password is wrong, retry.

#! /bin/bash

## Writen by Aming!
## Judging for a word if is your password.

pass="nihao123"
while :; do
    read -p "Please input the password:" word
    if [ $word != $pass ]; then
        echo "The password is wrong, retry."
    else
        exit
    fi
done

没有问题呀。只要你输不对是不会退出的。

回复帖子,请先登录注册

退出全屏模式 全屏模式 回复
评分
可选评分理由: