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

RE: Parameter expansion flags question



  > Placement of the quotes is important:
  >    for site in ${(f)"$($SITEMGR -i)":#}

OK, changing the placement of the quotes to the above fixes it. There's
just one thing I'm a little puzzled about - in the case where $SITEMGR
produces no output, won't "$($SITEMGR -i)" be the empty string? If so,
why is :# needed? It seems it will just replace an empty string with
another empty string?

Thanks,

    --- John

-----Original Message-----
From: Bart Schaefer [mailto:schaefer@xxxxxxxxxxxxxxxx] 
Sent: 11 May 2006 17:39
To: zsh-users@xxxxxxxxxx
Subject: Re: Parameter expansion flags question

[skipping around a bit]

On May 11, 10:59am, John Cooper wrote:
}
} One final thing - when I entered the "read" example into the shell as
} stated I got syntax errors. These were resolved by using "do" and
"done"
} instead of braces - is this to be expected?

Yeah, I messed up.  I never use the form with the braces, but you did
in your original "for" sample, so I tried to keep it with "while".  I
forgot that for "while" loops it only works when the first condition
is [[ ... ]] or (( ... )).

} Thanks for the detailed reply - it seems using "read" is the most
} straightforward approach. However, in the interests of learning more
} about expansions, I've been trying your suggestions and they don't
seem
} to work as expected.

Oh, duh.  I spaced that there were multiple lines of output from the
$SITEMGR program.  Obviously you need to process each line separately
before applying the subscript.

(This cold I'm coming down with must be affecting me worse than I
thought.)

} If I add the ":#pattern" operator to the original function, the "for"
} loop is still executed once in the case where $SITEMGR produces no
} output:

} delsites4 () {
}         for site in "${(f)$($SITEMGR -i):#}"

Placement of the quotes is important:

    for site in ${(f)"$($SITEMGR -i)":#}

If it still happens, I think it's because of Cygwin line termination.
Instead of an empty string when splitting with (f), you're getting a
string having a single carriage-return character.



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