我正在尝试编写一个bash脚本以将用户输入的答案转换为MD5并将其与MD5哈希进行比较,我已经必须看看是否是一样的,但是我得到了语法错误
Syntax error near unexpected token 'fi'
代码:
#!/bin/bash
# Check if you're right!
declare -x answer=6f22bf74918703932091343ba9c64402
echo "Enter your answer, follow by [ENTER]:"
read userAnswer
md5sum userAnswer > hashedAnswer
if [ answer == hashedAnswer ]
then
echo "Correct! You're right! It was him! Maybe I shou----"
echo "-You get run over, silenced before you can present your proof-"
else
echo "Wrong, try again!"
fi
任何帮助将不胜感激。
更改以下两行:
md5sum userAnswer > hashedAnswer
if [ answer == hashedAnswer ]
to:
hashedAnswer=$(printf "%s" "$userAnswer" |md5sum)
if [ "$answer" == "$hashedAnswer" ]
示例:
#!/bin/bash
# Check if you're right!
answer="b326b5062b2f0e69046810717534cb09 -"
echo "Enter your answer, follow by [ENTER]:"
read userAnswer
hashedAnswer=$(printf "%s" "$userAnswer" |md5sum)
if [ "$answer" == "$hashedAnswer" ]
then
echo "Correct! You're right! It was him! Maybe I shou----"
echo "-You get run over, silenced before you can present your proof-"
else
echo "Wrong, try again!"
fi
N.B:这里的答案是true