On 17/04/2017 15:10, Jeremy Henty wrote:
Pierre Labastie wrote:

First the &&: an instruction such as:
do_this && do_that
in bash does not fail, even  if "do_this" fails, because it is taken
by bash as semantically identical to:
if do_this; then do_that; fi
This is not correct because the exit status may be different:

     $ false && true ; echo $?
     1
     $ if false ; then true ; fi ; echo $?
     0

The bash  manpage section that  describes the  "if list; then  list; [
elif list; then list; ] ... [  else list; ] fi" construction says "The
exit status is  the exit status of the last  command executed, or zero
if no condition tested true.".

Regards,

Jeremy Henty
Oh you are right, thanks for the clarification. It is only when using set -e
that it works like that. From bash manpage about "set -e":

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 !.  If a
compound command other than a subshell  returns  a  non-
zero  status because a command failed while -e was being
ignored, the shell does not exit.

The effect is as I described, but you are right the semantics
is not the same.

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

Reply via email to