POSIX shell & Postgre Error capturing

Another thing is that you can directly test on the exit code:

if /usr/local/bin/psql database_name -U user_name <<EOF

        TRUNCATE table_name;

        \copy table_name (field1, field2, field3 ) from '/usr/home/dbupdater/update.txt' with NULL 'NULL'

EOF
then    echo "     Successfully loaded table." >> ${ERRMSG}
else    echo "     Error loading the table." >> ${ERRMSG]
fi

Also, my impression is that those { and } around statements (not those in the ${ }, those are very good imho) reveal that you learned another programming language earlier ')