I am trying to do a while do loop that asks for a password and returns if the password entered is incorrect. I have that part working however i want to modify it so that if a similar word is entered it will read "that is close but incorrect" and i cannot seem to get it working, being new in the linux. my code is simple:
read password
while [ "$password" != "hello" ]
do
echo "Wrong password, try again"
read password
done
I understand that you are satisfied with simple similarity, but this still means that you have to define the conditions under which you would regard two words as similar.
For example, you could see two words as similar, if they just differ in upper/lower case spelling. This would be easy to implement.
Thank you for your response. What i was thinking in terms of similarity was that if the "secret password" was let say unix and the person entered sky, the condition that is currently in the code would take the person to the echo "wrong password, try again" however, if they entered the word linux instead of unix, then the caption would read "close, but still not the correct password". I apologize, what i meant was to define one scenario, specifically linux not just any random word that is similar like munix or unixa. Hope i clarified my intent.
If you're OK to define the list of words, you can use something like this:
while read password; do
case $password in
linux)
echo "Close but no cigar!"
;;
unix)
echo "Eureka! You got it!"
break
;;
*)
echo "I don't think so, bud."
;;
esac
done