Results 1 to 4 of 4

Thread: Running A Loop for 6 minnutes (360 Seconds)

  1. #1
    Member
    Join Date
    Apr 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Question Running A Loop for 6 minnutes (360 Seconds)

    i need to print the same sentence for 6 minutes ..
    hopefully i think it can be done by a loop i tried below code but no success.

    Code:
    #!/bin/sh
    SECONDS=0
    while [[ SECONDS -lt 360 ]] ; do
     echo "Still Running"
    done

    please help me to sort this out.
    Thanks & Regards.
    Inshaf
    Last edited by nixcraft; 5th December 2012 at 02:02 PM.

  2. #2
    Never say die nixcraft's Avatar
    Join Date
    Jan 2005
    Location
    BIOS
    Posts
    4,374
    Thanks
    17
    Thanked 754 Times in 496 Posts
    Rep Power
    10

    Default

    Increase SECONDS by 1 and sleep for 1 second.
    Code:
    #!/bin/sh
     SECONDS=0
     while [ $SECONDS -lt 360 ] ; do
     echo "Still Running"
     SECONDS=`expr $SECONDS + 1`
     sleep 1
    done
    All [Solved] threads are closed by mods / admin to avoid spam issues. See Howto mark a thread as [Solved]


  3. #3
    Senior Member
    Join Date
    Aug 2011
    Posts
    367
    Thanks
    0
    Thanked 55 Times in 51 Posts
    Rep Power
    7

    Default

    hi,

    you need to increment the variable (which name should be lowercase: uppercase variable names are for environmental variables, not yours)
    Code:
    a=0
    a=$(( a + 1 ))
    echo $a
    1
    [[ is not sh/posix; adapt your shebang, or your code: know what shell you want to run.
    «A problem clearly stated is a problem half solved.»

  4. #4
    Member
    Join Date
    Apr 2012
    Posts
    37
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Rep Power
    0

    Default

    Great !!!

    Thats working perfectly.

    thanks for the valuable help ...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Help with loop in .sh script
    By chrisdemetriad in forum CentOS / RHEL / Fedora
    Replies: 1
    Last Post: 16th July 2012, 04:30 PM
  2. Perlcode-for loop
    By aish in forum Coding in General
    Replies: 0
    Last Post: 11th May 2011, 05:44 PM
  3. for loop question
    By billconner in forum Shell scripting
    Replies: 10
    Last Post: 24th August 2010, 01:58 AM
  4. batch cut first xx seconds of mp3 files
    By guzenkov in forum Linux software
    Replies: 0
    Last Post: 22nd May 2008, 09:52 PM
  5. mount -o loop ....
    By PeterGib in forum Linux software
    Replies: 3
    Last Post: 17th August 2007, 06:03 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41