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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T22:34:19+00:00 2026-05-21T22:34:19+00:00

Occasionally, I will run a command that has a lot of output. Occasionally, the

  • 0

Occasionally, I will run a command that has a lot of output. Occasionally, the last 30-40 lines of that output (a.k.a. the only part of the output I ever really see) is fine, but much further up, there was an error. I’d like to make it easier to notice that the command failed. To do so, I want the return code to be part of my prompt. So I took my $PS1:

[\D{%Y-%m-%d} \t] \[\e]0;\u@\h: \w\a\]\$

…and extended it to this:

[\D{%Y-%m-%d} \t] ${?/^0$/} \[\e]0;\u@\h: \w\a\]\$

This results in a prompt like this:

[2011-05-10 09:38:07] 0 soren@lenny:~$ 

However, I’d like to find a way to have it only include the exit code if it was non-0. How can I do that? Sure, I could use

$(echo \$? | sed -e blah)

but as lightweight as sed is, it’s still quite a bit more heavy weight than bash’s builtin stuff.

  • 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-21T22:34:19+00:00Added an answer on May 21, 2026 at 10:34 pm

    A little bit of printf abuse:

    printf '%.*s' $? $?
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

We recently received a report that our application will occasionally fail to run. I
Occasionally I will know that there is a .NET Framework function that returns a
Occasionally I run into this limitation using SQL Server 2000 that a row size
When I run DB.SubmitChanges(); I occasionally get an error that reads: Row not found
I have a rather simple command which I occasionally run: BEGIN TRAN T1; truncate
I am creating a desktop app that will sit on a PC and occasionally
Can anyone explain why the code below, when run, will occasionally result in some
I'm working on a 32-bit windows application that can occasionally run out of memory
I have some functions which occasionally (not always) will receive a callback and run
I am creating a django-based site that will serve flash apps that occasionally access

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.