On Mon, 2008-11-17 at 01:20 +0100, Julien Cristau wrote:
> On Fri, Nov 7, 2008 at 20:05:02 +0100, Adeodato Simó wrote:
>
> > > + # Just incase someone has removed their motd file.
> > > + [ ! -f /var/run/motd ] && touch /var/run/motd
> > > [ ! -f /var/run/motd.orig ] && cp /var/run/motd /var/run/motd.orig
> >
> > This is wrong for a `set -e` script. If those files exist, the left part
> > of the expression will fail, and the script will abort. The proper way
> > to do it is:
> >
> > [ -f /var/run/motd ] || touch /var/run/motd
> > [ -f /var/run/motd.orig ] || cp /var/run/motd /var/run/motd.orig
> >
> FWIW, set -e won't abort the script with the above code (well, unless
> touch or cp fail). From dash(1):
>
> -e errexit If not interactive, exit immediately if any
> untested command fails. The exit status of a com‐
> mand is considered to be explicitly tested if the
> command is used to control an if, elif, while, or
> until; or if the command is the left hand operand
> of an “&&” or “||” operator.
Which nicely explains why it was still working correctly for me.
Thanks for clearing that up!
--
Andrew Ruthven, Wellington, New Zealand
At home: andrew@etc.gen.nz | This space intentionally
| left blank.
Attachment:
signature.asc
Description: This is a digitally signed message part