I have below shell script
#! /bin/sh
for file in $(ls -l scripts/*.sql | awk '{print $NF}'); do
psql -h host -d db -U user -p port -f $file;
result=$?
if [ $result -ne 0 ]
then
exit 1
fi
done
$result always comes 0 even if I add some error to sql file. I want to exit shell script if any sql script throws error. Am I missing something in catching the error of last executed statement
lsand$()just loop through the globs.-bPrint failed SQL commands to standard error output. This is equivalent to setting the variable ECHO to errors.