How does shell get the exit status of a child shell while redirecting the output to a file?

scenario: the shell script completes the ETL work. The data extraction, transformation and loading operations correspond to three subscripts, all of which are atomic operations and need to be logged.
idea: call multiple child scripts to control the workflow through a single parent script, and get the exit status and output of the subscript at the same time.
problem: the following script cannot get the exit status of the subscript. You need to have standard output and error output on the screen and log it at the same time.

-sharp!/bin/bash
-sharpparent.sh
echo "You are in parent shell." | tee $0".log"
./child.sh; rc=$? | tee -a $0".log"
echo $rc
-sharp!/bin/bash
-sharpchild.sh
echo "You are in child shell."
exit 1
Aug.31,2021

  https://stackoverflow.com/que.

Menu