我想知道如何使用if / else语句来检查我的unix shell中的密码是否正确。
答案 0 :(得分:1)
以下是语法:
#!/bin/sh
# This is some secure program that uses security.
VALID_PASSWORD="secret" #this is our password.
echo "Please enter the password:"
read PASSWORD
if [ "$PASSWORD" == "$VALID_PASSWORD" ]; then
echo "You have access!"
else
echo "ACCESS DENIED!"
fi
bash-3.2$ Please enter the password:
secr
ACCESS DENIED!
bash-3.2$
bash-3.2$ Please enter the password:
secret
You have access!"
bash-3.2$
答案 1 :(得分:0)
read -s -e -p "Enter your password: " PASSWORD
if [ "$PASSWORD" == "password"}; then
echo "You have access!"
fi