Bash : preserve return value through pipe
The answer is eluding me, my apologies for this silly question :-)
I have a function logger that will log to screen or file based on some variables. This function kind of works, but provides a nasty thing: the return value of the calling command is lost (as one could expect); I tried to solve it like this: Code:
#!/bin/bash |
Sorry, I can't see why you're piping, this works:
Code:
#!/bin/bash |
Recent versions of bash provide a PIPESTATUS array variable, which holds all the exit codes of the most recent command chain.
"$?" will only hold the exit status of the most recently executed command, which will be the last one in the pipe chain. Edit: For details, always check the documentation. ;) From the bash man page: Quote:
|
Normally my logger() function would print the output of the provided command to screen, logfile or both (depending on a variable); So the implementation written above was only to illustrate what I tried.
In the specific case I try to do: Code:
svn export ${SVN_URL} | logger Code:
|
Ah, finally got it :-)
Code:
#!/bin/bash |
All times are GMT -5. The time now is 07:07 PM. |