bash command or function that doesn't change the error code
Hi!
I'm trying to write a bash function or command that will not alter the error level of the previous command. My application: I wat to create a $PS1 that outputs the error level of the last command (green=OK=0, red=error!=0) in my prompt ($PS1) within a function or script that returns the stdout colored string, I can never manage to KEEP the error level as it was.... As soon as I create a bash function or command that sets the color to grreen/red (echo/printf), they always return "0" as their error level. Even if I try things like that as "color.sh: Code:
#!/bin/bash How can I write a function or command that does not change the error level ($?)? |
This is tricky. A bash script runs in a new, clean bash instance so it doesn't get the $? from the caller. A function runs in the same instance as the caller, but anything you do will set $?. This includes doing:
Code:
errorLevel=$? Code:
function preserve() { |
You saved my life (... and my error level :P ). Thanks a lot!
|
All times are GMT -5. The time now is 10:03 AM. |