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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T13:49:25+00:00 2026-05-25T13:49:25+00:00

I have this bash shell-script command that causes date to run if make succeeds

  • 0

I have this bash shell-script command that causes date to run if make succeeds (terminates with zero exit status) and vice versa:

make && date

but now I want to process its output e.g.

make | sed s/a/A/

If I do

make | sed s/a/A/ && date

date runs even when make fails.

If I instead do

make && date | sed s/a/A/

the sed processes date‘s output instead of make‘s.

Would you know of any solution? Thanks!


P.S. I’ve tried these:

(make | sed s/a/A/) && date

date still runs when make fails.

(make && (date > /dev/null)) | sed s/a/A/

date doesn’t run when make succeeds.

  • 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-25T13:49:26+00:00Added an answer on May 25, 2026 at 1:49 pm

    If you do have a shell with process substitution (bash does, posix shell is not), than

    make > >(sed s/a/A/) && date
    

    should do the trick, except bash it does not wait for the sed (it seems zsh does, but I only tried it, not checked the doc), so the output of date can get before the last line of sed output. In plain posix shell, you can use a bit more complicated construct

    ((make && date >&3) | sed s/a/A/) 3>&1
    

    The date can again run before sed has processed everything, so it’s output can again come before the last line of sed output.

    If you want the date to only run after the sed has processed everything, your only chance is storing the make status somewhere. Something like:

    (make && touch make-succeeded) | sed s/a/A/
    rm make-succeeded 2>/dev/null && date
    

    abusing the fact, that if the file does not exist, rm (without -f) will exit with nonzero status and silencing it’s error message with redirection. As Fredrik has mentioned though, bash does in fact have a place where it does stash the exits status, so in bash you can:

    make | sed s/a/A/
    [ 0 -eq $PIPESTATUS[0] ] && date
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

For testing purposes I have this shell script #!/bin/bash echo $$ find / >/dev/null
I have this line in a useful Bash script that I haven't managed to
I have a Bash shell script that invokes a number of commands. I would
I have a bash shell script that loops through all child directories (but not
I am trying to make a new command which runs a shell script that
I have a shell script that saves the output of a command that is
I have an SVN repository. I have a shell/bash script that's designed to automatically
Question: I have a question that is apparently not answered by this already-asked Bash
I have a bash script file which starts with a function definition, like this:
I'm trying to write a shell script that, when run, will set some environment

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.