How do I access the history of the $? variable?
I know that $? returns the exit codes of the LAST executed program in your session, but is there a way to access the history of this variable such as during a pipelined set of commands in BASH and/or PERL? This would be especially useful when piping the output of your command through a grep, then testing the exit status of the original command--not grep's exit status.
I ran into this problem while writing a perl script that incorporates an rsync command.
Code:
system( "rsync -Kcpogltr --log-format=%n%L /from/dir/ /to/dir/ | grep -v /$" );
The above code will rsync the files from
/from/dir/ to the files in
/to/dir/. The
--log-format=$n%L combined with the
| grep -v /$ will print to the user all the files that have been synced (the grep bit hides the FOLDERS that normally get printed). After this call is made, I want to check the status of rsync and preform necessary error-checking, but I can't find a way around checking grep's status.
I understand that--programmatically with perl and/or bash--there is surely a way around this without the pipe, but I still want to know if there is a way to glimpse into the history of exit statues with the $? variable outside of this particular situation.
Thanks in advance!