help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Shopt to change default connector to '&&'


From: Hugues Morisset
Subject: Re: Shopt to change default connector to '&&'
Date: Thu, 9 Mar 2023 16:50:35 +0100

Hello,
Thanks for the responses,

> But... why?  What does your change allow you to do, which you couldn't
> do previously?

> An unmodified bash *already* lets you write code like this:

> if cmd1 && cmd2 && cmd3; then
>    cmd4 && cmd5
> fi

> It also lets you write code like this:

> if cmd1; cmd2; cmd3; then
>    cmd4; cmd5
> fi

> These two pieces of code have different meanings, of course.  The author
> of the script gets to choose which one is desired.

> Maybe I'm just missing something here.  Can you please explain in a little
> bit more detail?

Consider the following example:

cmd1
if cmd2; then
   cmd4 || cmd7
cmd5
fi
cmd6

To write it more sturdily, it would translate to something like this

cmd1 \
&& if cmd2; then
   { cmd4 || cmd7; } \
   && cmd5;
fi \
&& cmd6 ;

It imposes the author to be extra explicit, which I believe is harder
to write and read.

It's true that an unmodified bash already allows to explicitly write
'&&' or ';' to express desired behavior
This patch give the user the choice to use '&&' as a default command
separator when one is not explicitly given

(with newlines)



> And how is it meaningfully different from set -e?

As I understand there is a lot of quirks to set -e, one of which is a
command might be executed even if

the previous one failed.

It would be nice to have a way to express that a command is to be executed only
if the previous one succedded (which '&&' does) but without having to
write it everywhere.


The purpose of the patch is mainly to ease the writting of sturdy
scripts and make life easier.

Regards,

Hugues


reply via email to

[Prev in Thread] Current Thread [Next in Thread]