How to get both PIPESTATUS and output in bash script
- by Mustafa Serdar Sanli
I'm trying to get last modification date of a file with this command
TM_LOCAL=`ls -l --time-style=long-iso ~/.vimrc | awk '{ print $6" "$7 }'`
TM_LOCAL has value like "2012-05-16 23:18" after execution of this line
I'd also like to check PIPESTATUS to see if there was an error. For example if file does not exists, ls returns 2. But $? has value 0 as it has the return value of awk.
If I run this command alone, I can check the return value of ls by looking at ${PIPESTATUS[0]}
ls -l --time-style=long-iso ~/.vimrc | awk '{ print $6" "$7 }'
But $PIPESTATUS does not work as I've expected if I assign the output to a variable as in the first example. In this case, $PIPESTATUS array has only 1 element which is same as $?
So, the question is, how can I get both $PIPESTATUS and assign the output to a variable at the same time?