change

bh,lg.yu.,fgh,ry,.tyl,tyk,ty,ty,ty,.

What have you done so far? What is the problem that you're having? Most folks around here are happy to help but generally not willing to do the work for you.

Although homeworks are not allowed on this site, we could help if you show us what you have tried so far. Have a look at the while/break/done structure as well as the read function.

#!/bin/bash

  read -t 10 -p "Code : " code
  if [ "$code" == "boom" ]; 
  then
       echo "Bomb Disactivated"
  else
       echo "Booom!!"
  fi

(Now what i cant do is the 3 tries validation entry of the secret code)

you could use a C-style for loop:

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

There are two things, the number of tries and the running clock. The -t option of the read internal command takes care of the timout while the shell wait for the user input.

But you have to implement a general timer that will start as soon as the script starts. For that, use the date function converted in number of seconds since EPOCH. That's the idea. Try this:

#!/bin/bash
time=60
tries=3
start=$(date +%s)

left=$time
while true;do
    read -t $left -p "Code: " code
    ((tries--))
    left=$(($time-$(date +%s)+start))
    if (( $left<=0 || $tries==0 ));then
        echo "BOOOOM"
        break
    fi
    if [[ "$code" == "boom" ]];then
        echo "Correct. Bomb defused"
        break
    else
        echo "Wrong. Try again. There are $left seconds and $tries tries left."
    fi
done
exit

And.. please use the CODE tags for clarity.

Thanks Ripat i am going to try this code now

---------- Post updated at 03:57 PM ---------- Previous update was at 01:46 PM ----------

Ripat your code worked like magic !!Thank and Problem solved :slight_smile:

Do not post classroom or homework problems in the main forums. Homework and coursework questions can only be posted in this forum under special homework rules.

Please review the rules, which you agreed to when you registered, if you have not already done so.

More-than-likely, posting homework in the main forums has resulting in a forum infraction. If you did not post homework, please explain the company you work for and the nature of the problem you are working on.

If you did post homework in the main forums, please review the guidelines for posting homework and repost.

Thank You.

The UNIX and Linux Forums.