Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9120359
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T05:36:37+00:00 2026-06-17T05:36:37+00:00

Well i was just wondering how i can run like two while loops at

  • 0

Well i was just wondering how i can run like two while loops at the same time. I have heard of done& on a while loop and all but when i tried to use that it failed in the end. I have also heard using like a fork loop which i still don’t understand.

if anyone has ideas can you give me a little example script so I can understand.
Also I am not rejecting done& and fork loops just don’t know how to use them properly.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T05:36:38+00:00Added an answer on June 17, 2026 at 5:36 am
    #!/bin/bash
    
    while [ number == 1 ]; do sleep 1 echo "$time" done &
    
    while [ number == 1 ]; do sleep 1 time=$(echo "$time+1" | bc) done 
    

    When you run the above script, the while loops are run as separate processes and they can’t “see” the variable time as they’ll have them as their own local variables. In order to send the data across processes, you have to use an IPC mechanism.

    You can create a named pipe using mkfifo and send the time value from one process to another. The following a simple example of what you are trying to do:

    #!/bin/bash
    
    mkfifo mypipe #Creates a named pipe
    
    while read line<mypipe; 
    do 
      sleep 1
      echo "$line" 
    done & 
    
    while : ; 
    do 
      sleep 1 
      ((time=time+1))
      echo $time > mypipe
    done
    

    At the end of it, don’t forget to delete the pipe. Simply do: rm mypipe (you can see it in your current directory with: ls -l mypipe).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Well I was just wondering how can I put this semicolon separated string into
I have an autocomplete field and am just wondering how can i use it
Well, just to keep it simple: I have a webform. On it a button
I have some code that runs fairly well, but I would like to make
Just wondering if I could gather some constructive comments. Well, I am developing a
well I'm just wondering where the facebook api key went, now all I see
Current PHP version 4.3.8 Quick question: just wondering if i can enable the soap
Just wondering if anyone knows the keyboard shortcut to swap around two sides of
I use AVAudioPlayer to play music file. It just works well when playing via
I just finished this script it works well, but I am struggling to pass

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.