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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T07:24:29+00:00 2026-06-10T07:24:29+00:00

I want to trap the error inside the shell script, and then generate some

  • 0

I want to trap the error inside the shell script, and then generate some report for the reason for the error:

trap 'error_handler' ERR

In my error_handler function, I want to give the reason for why the ERR signal was caught (e.g. “permission denied”, “cannot find remote host”, etc.).

Is this possible?

  • 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-10T07:24:31+00:00Added an answer on June 10, 2026 at 7:24 am

    Not really. The only piece of information you are guaranteed to have available in your error handler is the exit status of the process that triggered the ERR, in $?. You don’t even know the name of the process or its process ID. I think the error handler is meant for general purpose clean-up before exiting a script, so it doesn’t matter which process had the non-zero exit status or why.

    You are better off reporting on or dealing with errors immediately when they happen, like so:

    rm foo || { echo "File removal failed"; }
    

    Note that most commands will print their own failure notices to standard error.

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

Sidebar

Related Questions

Want the function to sort the table by HP but if duplicate HPs then
I have a shell script I use for deployments. Since I want to capture
I am new to Outlook object model. I want to trap some events like
I want to trap values that are like this (in which there is not
I want to trap request for a my protocol from Firefox extension. For example
How to trap signal on ruby running on windows? I want to send signal/message
Want to run javascript function from parent window in child window Example I have
I have a simple function GetPageName(String PageFileName, String LangCode) defined inside a class file.
I have a database query that I am running inside an eval, to trap
I want to make DebugBreak for iPad and found that asm{trap} should work, but

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.