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

  • Home
  • SEARCH
  • 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 8065751
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T11:45:57+00:00 2026-06-05T11:45:57+00:00

I am trying to use xargs to call a more complex function in parallel.

  • 0

I am trying to use xargs to call a more complex function in parallel.

#!/bin/bash
echo_var(){
    echo $1
    return 0
}
seq -f "n%04g" 1 100 |xargs -n 1 -P 10 -i echo_var {} 
exit 0

This returns the error

xargs: echo_var: No such file or directory

Any ideas on how I can use xargs to accomplish this, or any other solution(s) would be welcome.

  • 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-05T11:45:58+00:00Added an answer on June 5, 2026 at 11:45 am

    Exporting the function should do it (untested):

    export -f echo_var
    seq -f "n%04g" 1 100 | xargs -n 1 -P 10 -I {} bash -c 'echo_var "$@"' _ {}
    

    You can use the builtin printf instead of the external seq:

    printf "n%04g\n" {1..100} | xargs -n 1 -P 10 -I {} bash -c 'echo_var "$@"' _ {}
    

    Also, using return 0 and exit 0 like that masks any error value that might be produced by the command preceding it. Also, if there’s no error, it’s the default and thus somewhat redundant.

    @phobic mentions that the Bash command could be simplified to

    bash -c 'echo_var "{}"'
    

    moving the {} directly inside it. But it’s vulnerable to command injection as pointed out by @Sasha.

    Here is an example why you should not use the embedded format:

    $ echo '$(date)' | xargs -I {} bash -c 'echo_var "{}"'
    Sun Aug 18 11:56:45 CDT 2019
    

    Another example of why not:

    echo '\"; date\"' | xargs -I {} bash -c 'echo_var "{}"'
    

    This is what is output using the safe format:

    $ echo '$(date)' | xargs -I {} bash -c 'echo_var "$@"' _ {}
    $(date)
    

    This is comparable to using parameterized SQL queries to avoid injection.

    I’m using date in a command substitution or in escaped quotes here instead of the rm command used in Sasha’s comment since it’s non-destructive.

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

Sidebar

Related Questions

I revieving the following error when trying use mysql_real_escape() function Fatal error: Call to
I have been trying use the edit_post_link() function to contain an image. All of
I'm trying to use xargs on a Cygwin Windows system to remove SVN files
I am trying use a javascript function while passing php variables in it. For
I am trying use a javascript function while passing php variables in it. For
I'm trying use the Str[fixnum] to return a specific portion of a string. #
I'm trying use preg_match in an IF statement and return false if a string
I am trying use the onClick() function in an activity for an android app.
i'm trying use facebook API to upload photo in my fan page. I downloaded
I am trying use gem tire to search in my application. I have tables

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.