Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

I am given an assignment like this: Write a Bash script that takes a *.tex file as command-line argument and checks if the file executes correctly without any errors. If it executes without any error and warning, assign a mark of 2 to that file. (1 mark if it compiled with a warning, and 0 marks if it shows an error).

I am able to assign marks for files which executed without any warnings and for files which gave a warning. Here, I am giving some of the lines of my code,

rm t.txt
pdflatex $1 >> t.txt
message=`tail -2 t.txt|grep -i "output"|cut -c 1-6`

After executing the command pdflatex, my script searches for appropriate words like "output" and "warning", and accordingly assigns marks. But in the case of a file which has errors, the pdflatex command exits only if we give a 'x'. Since it is expecting an 'x' from the user, it waits there. If I run the script, it is not showing any output; but if I print an x, it assigns the mark to that file as zero.

But I have to give this program to an automatic code-evaluator which checks for my code, and tells if my code is correct for all the cases...

How do I accomplish that?

share|improve this question
Workaround: tell pdflatex to behave, using -interaction nonstopmode. –  Stéphane Gimenez Dec 1 '11 at 14:32

2 Answers 2

In the general case, if you have a program in a shell script that tries to read input from the user, you can stop that by adding this at the top of your script:

exec < /dev/null

This tells the script to read input from /dev/null instead of from the keyboard. If any command after that tries to read input, it will immediately receive end-of-file.

share|improve this answer

Tell pdflatex not to wait for any interactive input ever:

pdflatex -interaction nonstopmode "$1"

If the command returns a nonzero status ($?), there was an error, so the mark is 0. Otherwise, test whether the log file (like $1, but with .log instead of the extension that's there already) contains the word Warning; if it does, the mark is 1, otherwise the mark is 0.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.