Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: curiosity with here document.

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

    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

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.

Messages sorted by: Reverse Date, Date, Thread, Author