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 7159309
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T13:12:35+00:00 2026-05-28T13:12:35+00:00

Based on This solution I am trying to develop a script that would limit

  • 0

Based on This solution I am trying to develop a script that would limit the number of processes running to 4. However as an alternative I want the jobs to be stored in an array that I reference by index. I have written the following:

todo_array[1]="echo start1;sleep 3;echo done1"
todo_array[2]="echo start2;sleep 3;echo done2"
todo_array[3]="echo start3;sleep 3;echo done3"
todo_array[4]="echo start4;sleep 3;echo done4"
todo_array[5]="echo start5;sleep 3;echo done5"
todo_array[6]="echo start6;sleep 3;echo done6"
todo_array[7]="echo start7;sleep 3;echo done7"
todo_array[8]="echo start8;sleep 3;echo done8"
todo_array[9]="echo start9;sleep 3;echo done9"

max_jobs=4

seq ${#todo_array[@]} | xargs -i --max-procs=$max_jobs bash -c $todo_array[{}]

however when I execute I am getting an empty 9 newlinex output.
What am I doing wrong?
Thanks

EDIT: I modified it to

seq ${#todo_array[@]} | xargs -i --max-procs=$max_jobs bash -c "$todo_array[{}]"

and I am getting the following weird output:

start1
start1
start1
start1
done1[2]
done1[3]
done1[1]
done1[4]
start1
start1
start1
start1
done1[5]
done1[6]
done1[7]
done1[8]
start1
done1[9]
  • 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-05-28T13:12:36+00:00Added an answer on May 28, 2026 at 1:12 pm

    Try this one:

    #!/bin/bash
    
    todo_array[1]="echo start1;sleep 3;echo done1"
    todo_array[2]="echo start2;sleep 3;echo done2"
    todo_array[3]="echo start3;sleep 3;echo done3"
    todo_array[4]="echo start4;sleep 3;echo done4"
    todo_array[5]="echo start5;sleep 3;echo done5"
    todo_array[6]="echo start6;sleep 3;echo done6"
    todo_array[7]="echo start7;sleep 3;echo done7"
    todo_array[8]="echo start8;sleep 3;echo done8"
    todo_array[9]="echo start9;sleep 3;echo done9"
    
    max_jobs=4
    
    for i in "${todo_array[@]}"
    do
        echo $i
    done | xargs -IX --max-procs=$max_jobs bash -c "X"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Update: This question was an epic failure, but here's the working solution. It's based
Based on this question it appears that the default template for CheckStyle will allow
Based on this question I don't want to litter my ready stuff waiting for
Based on this , how would you make ignoring parameters more succint? var m
This question is based on this thread in Meta . I would like to
I'm trying to develop a new application based on the standard Utility template, which
I've spent the last few hours trying to find the solution to this question
I am trying to develop a .NET 3.5 service application that uses: WCF for
I am trying to limit traffic to my website so that people trying to
Having no luck here trying to find a solution to this. I've set up

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.