Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > gnu.bash.bug > #16029
| 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 | 2020-03-13 21:52 +0700 |
| 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> |
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