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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T04:17:14+00:00 2026-06-15T04:17:14+00:00

I am encountering a very weird situation when wrapping a bash script call in

  • 0

I am encountering a very weird situation when wrapping a bash script call in echo $(). This is strange enough that I don’t know what code to present, so I will describe the general situation. I have a script, which we will call “run.sh”, and it has some output. This is generally formatted quite nicely, with whitespace and line breaks.

I am trying to compare this output with a value that I got when I ran it once previously. To do this, the code compares the “new” value with the old by checking if these two are the same, i.e.:

expression=$(./runProcess.sh "$process");
expected=$(cat UnitTests/expect-process-$process);
if [ "$expression" == "$expected" ]; then

Clearly to get a value of “old” to compare with future testings I need to compute $(./runProcess.sh) by hand. When I do this, I get a version of the output with significantly less whitespace. However it is clearly wrong, because the contents of ls turn up in the middle of it. By that I mean that I get the following type of output running these two commands:

./runProcess.sh g,g:

R2With2Gluons =

    + ncol*i_*pi_^2*A*g^2 * (
       - 17/24*d_(mu1,mu2)*d_(m1,m2)*p1.p1
       - 31/8*d_(mu1,mu2)*d_(m1,m2)*p1.p2
       - 17/24*d_(mu1,mu2)*d_(m1,m2)*p2.p2
       + 7/12*d_(m1,m2)*p1(mu1)*p1(mu2)
       + 1/24*d_(m1,m2)*p1(mu1)*p2(mu2)
       + 89/24*d_(m1,m2)*p1(mu2)*p2(mu1)
       + 7/12*d_(m1,m2)*p2(mu1)*p2(mu2)
       );

 0.01 sec out of 0.01 sec


echo $(./runProcess.sh g,g):
R2With3Gluons = + coeff(m1,m2,m3)*ncol*pi_^2*A*g^3 Auto Diagrams UnitTests colourCalc.frm form.set functions.frm output.frm process.frm process.mid qgraf2form.frm qgrafProcessor.py runProcess.sh runProcesses.sh test vertices.frm ( + 35/24*d_(mu1,mu2)*p1(mu3) - 35/24*d_(mu1,mu2)*p2(mu3) - 35/24*d_(mu1,mu3)*p1(mu2) + 35/24*d_(mu1,mu3)*p3(mu2) + 35/24*d_(mu2,mu3)*p2(mu1) - 35/24*d_(mu2,mu3)*p3(mu1) ); 0.40 sec out of 0.40 sec

And here is ls:

ls:
Auto              form.set          process.mid       runProcesses.sh
Diagrams          functions.frm     qgraf2form.frm    test
UnitTests         output.frm        qgrafProcessor.py vertices.frm
colourCalc.frm    process.frm       runProcess.sh

I can provide exact examples if necessary, but I hope this is illuminating enough. Why could this possibly be happening? I’m using bash on OS X Mountain Lion.

  • 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-15T04:17:15+00:00Added an answer on June 15, 2026 at 4:17 am

    Use more quotes!!!

    Try:

    echo "$(./run.sh)"
    

    instead. (Yes, with quotes).

    Try:

    old=$(./run.sh)
    echo "$old"
    

    you’ll have the correct output (with $old in quotes). Now, regarding your test, use, as advised by sampson-chen:

    [[ "$old" == "$(./run.sh)" ]]
    

    (you don’t need to quote the variables or the command substitution when assigning the variable old, but, as a general rule, you can use quotes every time). ((see Gordon Davisson’s excellent comments to this post, that I’ve actually upvoted, with a few caveats about globs and quoting variables inside [[ ... ]])).

    Edit. As you’ve edited your post, I see you’re using an inefficient cat. Instead of:

    expected=$(cat UnitTests/expect-process-$process)
    

    please use

    expected=$(< "UnitTests/expect-process-$process")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am encountering a very strange error for that says the following: Template is
I'm encountering a very strange problem: my delete actions in rails don't work anymore.
I am using Faye in a rails application and I'm encountering a very weird
I am encountering a very strange error with my project. I normally use the
I am encountering a very weird issue. I am trying to apply global styling
I'm encountering a very strange problem using g++ 4.1.2. I have a very basic
I'm encountering a very strange when I insert a new record into a table
I'm encountering a very strange error. I have an app ID defined in my
So I'm just getting started with F#, and I'm encountering a very weird issue
I'm encountering a very strange issue while debugging a unit test. If I debug

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.