Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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
share|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

1 Answer 1

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.

share|improve this answer

Your Answer

 
discard

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.