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

#!/bin/bash
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
link|improve this question
1  
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
feedback

1 Answer

up vote 0 down vote accepted

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

#!/bin/bash

fun() {
    echo "Error trapped"
}

trap fun ERR

asd

And here is how you should call it:

$ ./so.sh 2> /dev/null

The result is:

Error trapped

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

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

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