[ipxe-devel] question about double amp

Michael Brown mbrown at fensystems.co.uk
Sat Dec 11 14:10:41 UTC 2010

On Friday 10 Dec 2010 19:31:03 Duane Voth wrote:
> What should the double ampersand operator do in the following case?
>      imgfetch ${uuid}/foo.bar && goto :have_foo_bar
>      imgfetch foo.bar
>      :have_foo_bar
> The goto only executes if the ${uuid}/foo.bar fetch succeeds, but the
>  script aborts when this fetch fails.  Is this the expected behavior?

Yes.  As Thomas and Alessandro have said, either

  imgfetch ${uuid}/foo.bar && goto have_foo_bar ||
  imgfetch foo.bar

or just

  imgfetch ${uuid}/foo.bar || imgfetch foo.bar

would work.

The general principle is as follows:

In order to maintain backwards compatibility, any script line which produces 
an overall failure result will cause the script to terminate.

The && and || operators are left-associative, as is the case in most (all?) 
other languages that use them.

The empty command "" is deemed to be "do nothing, successfully", similar to 

Therefore, in the command

  imgfetch ${uuid}/foo.bar && goto have_foo_bar

if the imgfetch fails, this will evaluate to

  ( failure && <not-executed> )
  == failure

and so the script will terminate, whereas

  imgfetch ${uuid}/foo.bar && goto have_foo_bar ||

would evaluate to

  ( ( failure && <not-executed> ) || success )
  == ( failure || success )
  == success

and so the script will continue executing.


More information about the ipxe-devel mailing list