On 2019-03-27 13:50 +0100, Pierre Labastie via blfs-dev wrote:
> Hi,
> 
> When making scripts from the book (either by copy/paste
> or some use of xsltproc), the generated scripts have `&&' at
> the end of each line. It allows to not execute the following
> instructions if one instructions fail, but it defeats the use of
> "set -e". From the bash man page under the set builtin, for
> option -e (emphasis by me):
> ------------
> Exit  immediately  if a pipeline (which may consist of a
> single simple command), a list, or  a  compound  command
>   (see SHELL GRAMMAR above), exits with a non-zero status.
> *The shell does not exit if the  command  that  fails  is
> part  of  the command list immediately following a while
> or until keyword, part of the test following the  if  or
> elif  reserved  words, part of any command executed in a
> && or || list except the command following the final &&
> or ||, any command in a pipeline but the last, or if the
> command's return value is being inverted with !.*[...]
> ------------
> In short, with a construct like:
> ----
> set -e
> instruction A &&
> instruction B &&
> instruction C
> ----
> The script does not exit if either instruction A or instruction B fails,
> but the following instructions are not executed... This may lead to
> a script completing successfully, while the package was in fact not
> installed, or only partially installed or compiled!
> 
> So why do we use those `&&' in the book???
> 
> I've tried to automatically remove the `&&' in jhalfs, but it is not
> possible, because sometimes, the `... && ...' construct really really means
> if ...; then ...
> 
> There could be a solution: ask devs not to use `... && ...' when they mean
> if ...; then ...
> 
> Another is to not have `&&' at the end of line. Actually, what would we 
> lose?

When I manually type the command I don't use `&&'.  I just look at the terminal
to make sure a command succeeds before typing the next.

But when I copy the command, I think `&&' is useful or I have to run "bash -e".

Maybe we can change these "&&" to "&ampamp;" in XML so jhalfs can define it to
nothing or ";".  After all, now "&" is "&" and "&ampamp;" is actually
shorter than "&&" :).
-- 
Xi Ruoyao <[email protected]>
School of Aerospace Science and Technology, Xidian University

-- 
http://lists.linuxfromscratch.org/listinfo/blfs-dev
FAQ: http://www.linuxfromscratch.org/blfs/faq.html
Unsubscribe: See the above information page

Reply via email to