Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16029
| Path | csiph.com!xmission!news.snarked.org!news.linkpendium.com!news.linkpendium.com!panix!usenet.stanford.edu!not-for-mail |
|---|---|
| From | Robert Elz <kre@munnari.OZ.AU> |
| Newsgroups | gnu.bash.bug |
| Subject | Re: Are there any plans for more readable, modern syntaxes for If statements? |
| Date | Fri, 13 Mar 2020 21:52:59 +0700 |
| Lines | 35 |
| Approved | bug-bash@gnu.org |
| Message-ID | <mailman.2610.1584111228.2412.bug-bash@gnu.org> (permalink) |
| References | <CAAJSdjidSYg1yoWC7UbbLUUDF3ug9ekDtkOP7Er-JOjrLoDssQ@mail.gmail.com> <CAB+qc9AAPQbzp92tv-FOR4Kh+2UdZyRwGiPOfNegVqv5UFnU5Q@mail.gmail.com> <f1d0d39d-b6e6-c33e-7463-226f6994b99e@archlinux.org> <4305.1584111179@jinx.noi.kre.to> |
| NNTP-Posting-Host | lists.gnu.org |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=us-ascii |
| X-Trace | usenet.stanford.edu 1584111229 18693 209.51.188.17 (13 Mar 2020 14:53:49 GMT) |
| X-Complaints-To | action@cs.stanford.edu |
| Cc | Eli Schwartz <eschwartz@archlinux.org>, bug-bash@gnu.org |
| To | John McKown <john.archie.mckown@gmail.com> |
| Envelope-to | bug-bash@gnu.org |
| In-Reply-To | <CAAJSdjidSYg1yoWC7UbbLUUDF3ug9ekDtkOP7Er-JOjrLoDssQ@mail.gmail.com> |
| X-detected-operating-system | by eggs.gnu.org: GNU/Linux 3.x [generic] |
| X-Received-From | 2001:3c8:9009:181::2 |
| X-BeenThere | bug-bash@gnu.org |
| X-Mailman-Version | 2.1.23 |
| Precedence | list |
| List-Id | Bug reports for the GNU Bourne Again SHell <bug-bash.gnu.org> |
| List-Unsubscribe | <https://lists.gnu.org/mailman/options/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=unsubscribe> |
| List-Archive | <https://lists.gnu.org/archive/html/bug-bash> |
| List-Post | <mailto:bug-bash@gnu.org> |
| List-Help | <mailto:bug-bash-request@gnu.org?subject=help> |
| List-Subscribe | <https://lists.gnu.org/mailman/listinfo/bug-bash>, <mailto:bug-bash-request@gnu.org?subject=subscribe> |
| X-Mailman-Original-Message-ID | <4305.1584111179@jinx.noi.kre.to> |
| X-Mailman-Original-References | <CAAJSdjidSYg1yoWC7UbbLUUDF3ug9ekDtkOP7Er-JOjrLoDssQ@mail.gmail.com> <CAB+qc9AAPQbzp92tv-FOR4Kh+2UdZyRwGiPOfNegVqv5UFnU5Q@mail.gmail.com> <f1d0d39d-b6e6-c33e-7463-226f6994b99e@archlinux.org> |
| Xref | csiph.com gnu.bash.bug:16029 |
Show key headers only | View raw
Date: Fri, 13 Mar 2020 06:59:56 -0500
From: John McKown <john.archie.mckown@gmail.com>
Message-ID: <CAAJSdjidSYg1yoWC7UbbLUUDF3ug9ekDtkOP7Er-JOjrLoDssQ@mail.gmail.com>
| I do things like:
|
| test <some relational test> && { true_command1;true_command2; : ; } || {
| false_command1; false_command2; false_command3; }
That's OK, and at times I have been tempted that way, but it really is
easier to just do
if <some relational test>
then
true_command1
true_command2
else
false_command1
false_command2
false_command3
fi
Not only do you not need to remember that the ':' command (or "true") is
important, but the exit status of all of this will be whichever of
true_command2 or false_command3 that was executed, which can be
used in other tests later.
The cost of typing a few extra words to make things clearer, and having
the code not look quite so "look what I can do ma" (ie: less "cool") is
worth it to be more clear, and less likely to have bugs.
kre
Back to gnu.bash.bug | Previous | Next | Find similar
Re: Are there any plans for more readable, modern syntaxes for If statements? Robert Elz <kre@munnari.OZ.AU> - 2020-03-13 21:52 +0700
csiph-web