I have something like this:
find $1 | grep -E $2 | while read prom; do
if [[ $prom =~ (cmd-given) ]];
then
...
RETURN_PATH=$PWD
cd $WORKING_PATH
...
if [[ -s "stdout-delta" ]] || [[ -s "stderr-delta" ]] || [[ -s "status-delta" ]];
then
RET_ERROR=1
RESULT="FAILED"
else
RESULT="OK"
fi
...
echo "$TEST: $RESULT\n" > /dev/stderr
cd $RETURN_PATH
fi
done
I want to make test if in every folder that have cmd-given check for empty files x-delta. If any of these files is not empty I want to write FAILED and set return code to 1. But I want to check all folders so I think that I use variable, set it to 1 and at the end check if it is equal to 1 that exit 1 else exit 0. But there is problem, when I get out from that loop, I don´t have 1 in my variable. So how should I solve this?
The loop runs in a subprocess, so you would have to use some form of IPC to communicate with the original process (the shell).
The easiest solution is probably to just echo your error message to stdout and add a pipe after the while loop to parse the output. A simple grep should suffice. Just make sure no other command can write ‘FAILED’ to stdout.
Edit: temporary file based solution:
Edit 2: function based solution