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
  • 1
    I am trying to fathom why exactly you would not want to know where the error is coming from... 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

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:

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

The result is:

Error trapped

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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