On 3/27/19 9:44 AM, Roger Koehler via blfs-dev wrote:
On Wed, Mar 27, 2019, 6:52 AM Pierre Labastie via blfs-dev <[email protected] <mailto:[email protected]>> 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?


For me, it makes it easy to see which commands go together when editing the jhalfs-generated scripts. For example, to remove the generation of API documentation when I don't have the necessary tools installed.

However, I would gladly forego that luxury for the peace of mind in knowing that when a build completes successfully, it actually installed everything.

I think most users just copy/paste the instructions instead of scripting. In that case using && makes the instructions fail on the problematic instruction instead of continuing to the rest of the commands in the block. In places like xorg-libs where we create a script-like environment using 'bash -e', we do not use &&.

Personally I wrap my scripts in

{
 a &&
 b
}
if [ $PIPESTATUS -ne 0 ]; then exit 1; fi;

  -- Bruce
--
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