change


Login or Register for Dates, Times and to Reply

 
Thread Tools Search this Thread
Homework and Emergencies Homework & Coursework Questions change
# 1  
Java change

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

Last edited by frankycool; 10-21-2009 at 10:46 AM..
# 2  
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.
# 3  
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.
# 4  
Java Hi guys this is what i have done so far

Code:
#!/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)

Last edited by Franklin52; 10-02-2009 at 05:43 AM.. Reason: Please use code tags!
# 5  
you could use a C-style for loop:
Code:
for (( i=1 ; i<=3 ; i++ )); do echo $i; done
1
2
3

# 6  
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:

Code:
#!/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.

Last edited by ripat; 09-29-2009 at 02:14 PM.. Reason: some fixing
# 7  
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 Smilie
Login or Register for Dates, Times and to Reply

Previous Thread | Next Thread
Thread Tools Search this Thread
Search this Thread:
Advanced Search

Test Your Knowledge in Computers #669
Difficulty: Medium
802.11 technology has its origins in a 1985 ruling by the U.S. FCC that released the ISM band for unlicensed use.
True or False?

8 More Discussions You Might Find Interesting

1. SCO

How to change raid controller driver ? (hardware change)

Hello I'm trying to virtualize an instance of Sco Unix 5.0.5 in VirtualBox (called VM-A) , but sco I have problems set to launch with the new raid controller . The physical machine has a raid controller adaptec (alad driver) but VirtualBox uses buslogic (blc driver) What ... (3 Replies)
Discussion started by: flako
3 Replies

2. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (7 Replies)
Discussion started by: ust3
7 Replies

3. Shell Programming and Scripting

Change the content of files but not change the date

I have 100 files in a directory , all the files have a word "error" and they are created in different date . Now I would like to change the word from "error" to "warning" , and keep the date of the files ( that means do not change the file creation date after change the word ) , can advise what can... (0 Replies)
Discussion started by: ust3
0 Replies

4. Shell Programming and Scripting

ksh; Change file permissions, update file, change permissions back?

Hi, I am creating a ksh script to search for a string of text inside files within a directory tree. Some of these file are going to be read/execute only. I know to use chmod to change the permissions of the file, but I want to preserve the original permissions after writing to the file. How can I... (3 Replies)
Discussion started by: right_coaster
3 Replies

5. Shell Programming and Scripting

change wc -l

Hi, I would like realize a script that it can change " wc -l" with "wc -l | sed 's/ //g'", but my problem is that i can have a pipe ,a variable ( many variable different) or a file after wc -l ?how i could test this several case ? wc -l | cut -d' ' -f1` if wc -l ${F} | awk... (1 Reply)
Discussion started by: francis_tom
1 Replies

6. Solaris

Change IP

hello How can i change the ip address on my solaris sun 9 server ? thank you (7 Replies)
Discussion started by: pascalbout
7 Replies

7. Post Here to Contact Site Administrators and Moderators

Want to change my Name

Hello, Pls change my login name to Awadhesh instead of awadhesh if possible. it will be more better if it become Awadhesh Pandey. Thanks a lot. Awadhesh (2 Replies)
Discussion started by: Awadhesh
2 Replies

8. Cybersecurity

How to change ip ?

hi , Is there anyway to change ip on sco5.04 i tried using netconfig on the prompt but gives me error . how do u manually change ip cant use acoadmin and netconfig .... thx art (2 Replies)
Discussion started by: art_malabanan
2 Replies

Featured Tech Videos