[Nottingham] bash syntax: elif

Duncan John Fyfe djf at star.le.ac.uk
Tue Jul 27 10:22:52 BST 2004


On Tue, 27 Jul 2004, David Wolfson wrote:


> but tried changing it to this:
>
> if [ $? -eq 0 ]
> 	then
> 	echo 'pepdm1 virus sweep clear'|mail -s 'sweep' eaxdrw at nottingham.ac.uk
> elif [$? -eq 1 ]
       ^^
> 	then
> 	echo 'pepdm1 virus sweep interupted'|mail -s 'sweep' eaxdrw at nottingham.ac.uk
> elif [$? -eq 2 ]
       ^^
> 	then
> 	echo 'pepdm1 virus sweep error'|mail -s 'sweep' eaxdrw at nottingham.ac.uk
> elif [$? -eq 3 ]
       ^^
> 	then
> 	echo 'pepdm1 virus detected'|mail -s 'sweep' eaxdrw at nottingham.ac.uk
> fi

At the very least your missing some spaces ie. [ $?
Yes, bash can be a sensitive wee soul when it comes to spaces.

You should add a final 'else' clause as well to catch
problems wich don't conform to the documentation.

Have fun,
Duncan




More information about the Nottingham mailing list