I am running this while loop in a script to take mysqldump and compress it, but I want to exit the script if the table doesn't exist. Below is what I have tried.
while read TABLES; do
sudo mysqldump $DB $TABLES | gzip -f > $DB.$TABLES.sql.gz
if [ $? != 0 ]; then
echo "mysqldump Query executed with error !!"
exit 1
fi
done < file
But this will give the exit status of gzip -f, but not of mysqldump. I know I can get the exit status of mysqldump if I am not using gzip there, but is there any way in this method to get the exit ststus for mysqldump?