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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T17:28:17+00:00 2026-06-18T17:28:17+00:00

I want to make a build chain script, and I don’t want it to

  • 0

I want to make a build chain script, and I don’t want it to perform until the end if there are error during compilation.

It’s the first time I write a more “elaborated” script in bash, and it just doesn’t work:

  1. it doesn’t echo ERROR although I have lines with the word error in it
  2. whatever the value of testError, the script just hangs in the line

this is the code:

testError=false

output=$(scons)
while read -r line; do
    if [[ $line == .*[eE]rror.* ]] ; then echo 'ERROR' ; $testError = true ; fi #$testError = true fi
done

echo $testError
if  $testError  ; then exit ; fi;

... other commands

EDIT: Following all posters answers and Bash setting a global variable inside a loop and retaining its value — Or process substituion for dummies and How do I use regular expressions in bash scripts?,
this is the final version of the code.
It works:

testError=false

shopt -s lastpipe
scons | while read -r line; do
  if [[ $line =~ .*[eE]rror.* ]] ; then
    echo -e 'ERROR' 
    testError=true 
  fi 
  echo -e '.'
done

if  $testError  ; then
    set -e 
fi
  • 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-18T17:28:19+00:00Added an answer on June 18, 2026 at 5:28 pm

    You set the value of testError in a subshell induced by your pipeline. When that subshell exits (at the end of the pipeline), any changes you made disappear. Try this:

    while read -r line; do
       if [[ $line == .*[eE]rror.* ]] ; then
         echo -e 'ERROR' 
         testError=true 
       fi #$testError = true fi
    done < <( scons )
    

    or, if you don’t want or can’t use process substitution, use a temporary file

    scons > tmp
    while read -r line; do
      if [[ $line == .*[eE]rror.* ]] ; then
        echo -e 'ERROR' 
        testError=true 
      fi #$testError = true fi
    done < tmp
    

    This eliminates the pipeline, so the changes to testError persist after the while loop.

    And, if your version of bash is new enough (4.2 or later), there is an option that allows the while loop at the end of a pipeline to execute in the current shell, not a subshell.

    shopt -s lastpipe
    scons | while read -r line; do
      if [[ $line == .*[eE]rror.* ]] ; then
        echo -e 'ERROR' 
        testError=true 
      fi #$testError = true fi
    done
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I use Zend framework to build the forms, I want to make the edit
I want to build a new design into WP (not make a theme for
i want to build my android project with ndk so i created my make
I want make a bash script which returns the position of an element from
i want to make VS copy the .lib-file it created after the build process
I want to build a lightweight dashboard with Highcharts. First, look at this graphic
I want to build a back end of a general web form which contains
I want make to build all .cpp in the directory with tracking header changes.
I'm a student and i want make a build tool as a side project
After I make a build I want to copy some files into my Xcode

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.