Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am using Fedora 14 and when I am executing a file:

asd #assuming this command does not exist

I am getting following error: /path/to/file: line 2: asd: command not found

I want to format it so it outputs error in same way as it would when it was executed from terminal:

$ asd
bash: asd: command not found
share|improve this question
I am trying to fathom why exactly you would not want to know where the error is coming from... – Ignacio Vazquez-Abrams Jun 8 '11 at 9:28
ScreenShot - I am making kind of terminal in-game and I am using script to execute the file with given interval. (when I mistyped pwd as pd long error showed up) – Sebi Jun 8 '11 at 9:37
up vote 0 down vote accepted

So maybe this example would help you. Here is the script content:


fun() {
    echo "Error trapped"

trap fun ERR


And here is how you should call it:

$ ./ 2> /dev/null

The result is:

Error trapped

The signal ERR is trapped every time a command returns non-zero.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.