I am experiencing, in my opinion, a not expected behavior when reading lines from stdin in a loop inside a bash script.
The section of the script which has that behavior looks like:
........
echo "$PROP_VALUE" | tr ':' 'n' | while read FILE_MAPPING
do
errLog "entering to process FILE_MAPPING='$FILE_MAPPING'"
BASE_FILE_TO_MAP="$( echo "$FILE_MAPPING" | awk -F'=' '{ print $1 }' )"
IS_COMPOUND_FILENAME="$( echo "$BASE_FILE_TO_MAP" | grep "/" | wc -l )"
MODEL_FILE_TO_COPY="$( echo "$FILE_MAPPING" | awk -F'=' '{ print $2 }' )"
(( IS_COMPOUND_FILENAME > 0 )) && { errLog "'$BASE_FILE_TO_MAP' does not seem to be a basename, at '$MACHINE_PARTICULAR_INPUT_PROP_FILENAME', for label:'$MAPPING_LABELNAME'"; exit 11; }
find "$DIRECTORIO_CONFIGURACION_GENERADA" -name "$BASE_FILE_TO_MAP" | while read FILE_TO_BE_REPLACED
do
FILE_TO_REPLACE_TO="$( get_paths_relative_to.py "$MACHINE_PARTICULAR_INPUT_PROP_FILENAME" "$MODEL_FILE_TO_COPY" )"
errLog " replacing '$FILE_TO_BE_REPLACED' from: '$FILE_TO_REPLACE_TO'"
cp -a "$FILE_TO_REPLACE_TO" "$FILE_TO_BE_REPLACED" || { errLog "Error when copying '$FILE_TO_REPLACE_TO' to '$FILE_TO_BE_REPLACED'"; exit 3; }
done
MY_RESULT=$?
errLog "$? [1] = $MY_RESULT"
(( MY_RESULT != 0 )) && exit 4
done
MY_RESULT=$?
errLog "$? [2] = $MY_RESULT"
exit $MY_RESULT
The value for PROP_VALUE is an equivalent one to: “xmlTransformation.xml=../../../../20260715.latestRules/TransformationRulesXml_GE.xml”
In a nutshell, the script aims to replace some files in a configuration instance, replacing them by the latest versions of those files depending on a configuration value.
And the output for the unexpected result execution is:
...
replacing './XXXXXXXXXXXXXXXXXX/de/xmlTransformation.xml' from: './ZZZZZZZZZZZZZZZZZZZZZZ/../../../../20260715.latestRules/TransformationRulesXml_GE.xml'
$? [1] = 0
$? [2] = 1
and the script returns a non-successful result to its caller.
I have not the experience to be sure that it is not the expected behavior, but it seems logical to get a result of 0 (success), and in my one liner checks emulating the look and even the double loop, the result I get is zero.
Do you know if the is any way to detect a failure inside the external loop at root level? Is there any way to detect a success of the external loop at root level?