I am using following script to compile Latex documents to pdf on commandline in Linux:
#! /bin/bash
NAME=`echo "$1" | cut -d'.' -f1`
pdflatex -file-line-error -halt-on-error $NAME.tex
xdg-open $NAME.pdf
It works, but even if there is error in compilation by pdflatex, xdg-open line runs and shows any previously created pdf file.
How can I add a conditional statement for last line of code, i.e. xdg-open should run only if compilation in previous line by pdflatex is successful? Else, it should give error message and not try to show any pdf file. Does pdflatex return any error code that can be checked in bash script? Thanks for your help.