zsh-users
 help / color / mirror / code / Atom feed
From: Bart Schaefer <schaefer@brasslantern.com>
To: zsh-users@zsh.org
Subject: Re: curiosity with here document.
Date: Thu, 26 Nov 2015 17:56:25 -0800	[thread overview]
Message-ID: <151126175625.ZM22214@torch.brasslantern.com> (raw)
In-Reply-To: <5657939E.7070106@eastlink.ca>

On Nov 26,  3:19pm, Ray Andrews wrote:
}
} lesson learned.

Except it's the wrong lesson!  What you *ought* to learn is, first, that
for purposes of determining the "truth value" (zero or nonzero return
status),

    if command1; command2; command3; then ...

is the same as

    function three_commands {
	command1; command2; command3
    }
    if three_commands; then ...

And second, that [[ ... ]] is just a command like any other command,
it's not magically connected to "if".  Further, ":" is also a command
like any other command.

And third, that a here-document is just the standard input of the
command it follows, so

    : <<END
    some stuff
    END

is (again for purposes of determining truth value) the same as

    :

and the colon command is "true" for purposes of if/while/until/etc.,
it has a return status of zero.  So what you've written is

    if [[ ... ]]; : ; then ...

and colon is true and is the last command before the "then", so the
true branch is taken.

The here-document itself has no true or false interpretation, and the
presence of the here-document is not what is causing "if" to behave
the way it does.


  reply	other threads:[~2015-11-27  1:56 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-11-26 18:37 Ray Andrews
2015-11-26 19:01 ` ZyX
2015-11-26 19:03 ` ZyX
2015-11-26 23:19   ` Ray Andrews
2015-11-27  1:56     ` Bart Schaefer [this message]
2015-11-27  2:29       ` Ray Andrews

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=151126175625.ZM22214@torch.brasslantern.com \
    --to=schaefer@brasslantern.com \
    --cc=zsh-users@zsh.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.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

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).