I have the following:
test.sh
. Foo.sh
Foo.bar
Foo.baz
Foo.blah
and
Foo.sh
function Foo.bar() {
echo 'I am a bar!'
}
function Foo.baz() {
echo 'But, I am a baz!'
}
function Foo.error() {
# I should suppress the 'command not found' error based on the pattern '^Foo\.([^:]+):'
# If the pattern is matched, I'll need to perform some action based on the captured pattern.
}
trap Foo.error ERR
This is what I get when I run test.sh
:
$ ./tesh.sh
I am a bar!
But, I am a baz!
./test.sh: line 5: Foo.blah: command not found
I would like to:
- suppress the
command not found
error. - pass the
Foo.blah: command not found
text toFoo.error()
to perform some action based on the error.
I suppose I could redirect errors to /dev/null like so:
./test.sh 2> /dev/null
But this is not as elegant as I'd like it to be. In any case, it still doesn't give my error() function access to the error text.