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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T23:39:49+00:00 2026-05-28T23:39:49+00:00

Background: I’m working on quickly calling bash command line expressions inside of SGE’s job

  • 0

Background:

I’m working on quickly calling bash command line expressions inside of SGE’s job submission program qSub in parallel. While doing so, I was attempting to submit an expression (as an argument) to be ran inside of another script like so:

./runArguments.sh grep foo bar.txt > output.txt

runArguments.sh looks like this:

#!/bin/bash  
${1} ${2} ${3} etc....to 12

The idea is that I want “grep foo bar.txt > output.txt” to be evaluated in the script…NOT ON THE COMMAND LINE. In the example above, “grep foo bar.txt” will evaluate during runArguments.sh execution, but the output redirection would be evaluated on the command line. I eventually found a working solution using “eval” that is shown below, but I do not understand why it works.

Question(s)

1) Why does

./runArguments.sh eval "grep foo bar.txt > output.txt"

allow the eval and the expression to be taken as arguments, but

./runArguments.sh $(grep foo bar.txt > output.txt)

evaluates on the command line before the script is called? (the output of $(grep…) is taken as the arguments instead)

2) Is there a better way of doing this?

Thanks in advance!

  • 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-28T23:39:49+00:00Added an answer on May 28, 2026 at 11:39 pm

    Your first question is a bit hard to answer, because you’ve already answered it yourself. As you’ve seen, command substitution (the $(...) or `...` notation) substitutes the output of the command, and then processes the result. For example, this:

    cat $(echo tmp.sh)
    

    gets converted to this:

    cat tmp.sh
    

    So in your case, this:

    ./runArguments.sh $(grep foo bar.txt > output.txt)
    

    runs grep foo bar.txt > output.txt, grabs its output — which will be nothing, since you’ve redirected any output to output.txt — and substitutes it, yielding:

    ./runArguments.sh
    

    (so your script is run with no arguments).

    By contrast, this:

    ./runArguments.sh eval "grep foo bar.txt > output.txt"
    

    does not perform any command substitution, so your script is run with two arguments: eval, and grep foo bar.txt > output.txt. This command inside your script:

    ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12}
    

    is therefore equivalent to this:

    eval grep foo bar.txt '>' output.txt
    

    which invokes the eval built-in with five arguments: grep, foo, bar.txt, >, and output.txt. The eval built-in assembles its arguments into a command, and runs them, and even translates the > and output.txt arguments into an output-redirection, so the above is equivalent to this:

    grep foo bar.txt > output.txt
    

    . . . and you already know what that does. 🙂


    As for your second question — no, there’s not really a better way to do this. You need to pass the > in as an argument, and that means that you need to use eval ... or bash -c "..." or the like in order to “translate” it back into meaning output-redirection. If you’re O.K. with modifying the script, then you might want to change this line:

    ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12}
    

    to this:

    eval ${1} ${2} ${3} ${4} ${5} ${6} ${7} ${8} ${9} ${10} ${11} ${12}
    

    so that you don’t need to handle this in the parameters. Or, actually, you might as well change it to this:

    eval ${@}
    

    which will let you pass in more than twelve parameters; or, better yet, this:

    eval "${@}"
    

    which will give you slightly more control over word-splitting and fileglobbing and whatnot.

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

Sidebar

Related Questions

Background The Von-Neumann architecture describes the stored-program computer where instructions and data are stored
Background: I'm working through the Programming Collective Intelligence book by Toby Segaran; specifically the
Background: My coworker and I are maintaining a million-line legacy application we inherited. Its
Background : I'm working on a management page for musicians. Lets say the user
Background: My employeer at my non-programming job knows that I am an undergraduate CS
Background: I have a little video playing app with a UI inspired by the
Background: At my company we are developing a bunch applications that are using the
Background: Some time ago, I built a system for recording and categorizing application crashes
Background: I need to reserve an amount of memory below 0xA0000 prior to my
Background I am writing and using a very simple CGI-based (Perl) content management tool

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.