954,123 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Bomb timer and secret code in shell

Please I want to build a program in scripting that will start a timer from 60 seconds and decrement every second.There should be an input where the user should be able to enter the secret password to dis-activate the timer-bomb.If the user fails to enter the correct password 3 times or the timer reaches 0 without any entries,a message should be displayed as Bomb Exploded else a message should be displayed as Bomb Defused.Beneath is the code i tried but its not working as i wish,so please help me if necessary.

#!/bin/bash



  read -t 10 -p "Code : " code

for (( i=1 ; i<=3 ; i++ )); do echo $i;

  if [ "$code" == "boom" ]; 

  then

       echo "Bomb Disactivated"

  else

       echo "Bomb Exploded"



  fi
frankycool
Newbie Poster
15 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 
password=boom
n=0
for n in 1 2 3
do
  read -ep "Code: " code
  [ "$code" = "$password" ] && break
done

if [ "$code" = "$password" ]
then
  echo "Bomb Disactivated"
else
  echo "Bomb Exploded"
fi
cfajohnson
Junior Poster
196 posts since Dec 2008
Reputation Points: 25
Solved Threads: 23
 

thanks it helped

frankycool
Newbie Poster
15 posts since Sep 2009
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You
View similar articles that have also been tagged: