Hello folks,
I've experimented a bit with bash's trap command and I've found rather strange behaviour. Searching threads about it on the forum gave me no useful results.
Here my question is. Consider this little script:
The output is:
So, as you can see, any text that follows whitespace in the ERRORR's value is ignored. I still can add \t or some other escape sequences instead of whitespace and it will work. But is there any way to quote $ERRORR variable properly in the trap?
I've experimented a bit with bash's trap command and I've found rather strange behaviour. Searching threads about it on the forum gave me no useful results.
Here my question is. Consider this little script:
Code:
#!/usr/local/bin/bash
function trapping() {
local error_message="$1"
echo -e "error is $1";
}
trap "{ trapping \$ERRORR ; }" EXIT
ERRORR="Your script does not work."
echo -n "Please, write here anything: "
read MYVAL
test -z $MYVAL && \
{
ERRORR="Some error message."
exit 0
}
The output is:
Code:
Please, write here anything:
error is Some
So, as you can see, any text that follows whitespace in the ERRORR's value is ignored. I still can add \t or some other escape sequences instead of whitespace and it will work. But is there any way to quote $ERRORR variable properly in the trap?