From: Norman Wilson <norman@oclsc.org>
To: tuhs@tuhs.org
Subject: [TUHS] SH script formatting
Date: Tue, 29 Sep 2020 15:15:06 -0400 [thread overview]
Message-ID: <1601406910.6529.for-standards-violators@oclsc.org> (raw)
if test; then
stuff
and
if test
then
stuff
are functionally equivalent. I wouldn't say one or the
other `is preferred.' I use the former because I think
it's a little more readable because more compact. But
it's really a matter of style, like whether you write
if (test) {
(multi-statement block)
or
if (test)
{
(multi-statement block)
I have a stronger opinion about those who use overly-
cryptic constructions like
test && {
shell commands
}
because it means exactly the same thing as
if test; then
shell commands
but is more obscure to read. But again it's a question
of style, not of dogma.
As an aside, I think one excuse that is sometimes used
for that sort of construct is when it's
test || {
commands
}
because Bourne's original shell had no not operator.
For a long time after shell functions appeared, I would
add this function to any of my shell scripts that needed
it:
not() {
if "$@"; then
return 1
else
return 0
}
so I could say
if not test; then
commands
fi
Modern Bourne-shell descendants have a built-in ! operator:
if ! test; then
commands
fi
I'm not keen on most of what has been stuffed into bash and
ksh and the like, but ! is a real improvement. I believe
POSIX mandates it, and I think they're right.
Norman Wilson
Toronto ON
next reply other threads:[~2020-09-29 19:16 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-09-29 19:15 Norman Wilson [this message]
-- strict thread matches above, loose matches on Subject: below --
2020-09-29 18:42 David Barto
2020-09-29 19:29 ` John Cowan
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1601406910.6529.for-standards-violators@oclsc.org \
--to=norman@oclsc.org \
--cc=tuhs@tuhs.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).