当前位置: 技术问答>linux和unix
如何在shell脚本里用正则表达式限制输入格式
来源: 互联网 发布时间:2017-05-07
本文导语: echo -ne "n$MESSAGE for $THEUSER (minimum 8 chars. with one numeric/special char.) : " stty -echo read THEPASSWORD stty echo 读进来的THEPASSWORD 如何符合上面的要求呢,如何检查? | #!/bin/sh read -p 'Set your password(your p...
echo -ne "n$MESSAGE for $THEUSER (minimum 8 chars. with one numeric/special char.) : "
stty -echo
read THEPASSWORD
stty echo
读进来的THEPASSWORD 如何符合上面的要求呢,如何检查?
stty -echo
read THEPASSWORD
stty echo
读进来的THEPASSWORD 如何符合上面的要求呢,如何检查?
|
#!/bin/sh
read -p 'Set your password(your password must contain a minimum of 8 chars with one numeric/special char.) ' password
if ! echo $password | egrep '[a-z]{7,}([0-9]|[!@#$%&^*]){1}' 1>/dev/null;then
echo "your password is invalid"
fi
|
THEPASSWORD=ladofwind@123
n=0
echo "$THEPASSWORD" | grep -q "........"
if [ $? == 0 ]; then
echo [minimum 8 chars] yes
n=`expr $n + 1`
else
echo [minimum 8 chars] no
fi
echo "$THEPASSWORD" | grep -q "[0-9]"
if [ $? == 0 ]; then
echo [one numeric] yes
n=`expr $n + 1`
else
echo [one numeric] no
fi
echo "$THEPASSWORD" | grep -q "[^0-9a-zA-Z]"
if [ $? == 0 ]; then
echo [one special] yes
n=`expr $n + 1`
else
echo [one special] no
fi
if [ $n == 3 ]; then
echo password valid
else
echo password invalid
fi
|
厉害。佩服佩服。