From: "John Cooper" <john.cooper@eu.citrix.com>
To: <zsh-users@sunsite.dk>
Subject: Parameter expansion flags question
Date: Wed, 10 May 2006 10:22:12 +0100 [thread overview]
Message-ID: <DD74FBB8EE28D441903D56487861CD9D0971728B@lonpexch01.citrite.net> (raw)
[-- Attachment #1: Type: text/plain, Size: 1477 bytes --]
I've been writing a function to run a command, extract the first word of
each line of the command's output and use that as a parameter to another
command. The command's output looks like this:
1:/Citrix/Pres WI
http://RA.eng.citrite.net/Citrix/Pres 4.5.5.1159
c:\inetpub\wwwroot\Citrix\Pres
1:/Citrix/Pres2 WI
http://RA.eng.citrite.net/Citrix/Pres2 4.5.5.1159
c:\inetpub\wwwroot\Citrix\Pres2
After some trial-and-error I finally have the following function:
SITEMGR=c:/Program\ Files/Citrix/Web\
Interface/4.5/sitemgr.exe
delsites() {
for site in "${(f)$($SITEMGR -i)}" ; {
sitepath=${${=site}[1]}
[[ -n "$sitepath" ]] && $SITEMGR -r
"WICurrent=$sitepath"
}
}
I'm new to the zsh parameter expansion flags, but I've gathered the
${(f) will take the command's output a line at a time, and the ${=site}
will then split each line into words, allowing me to grab the first word
of each line.
Is there a better (or simpler!) way to do this? When the command has no
output, the `for' loop is still executed once (seemingly because the
command is within double-quotes) and is the reason for checking that the
length of $sitepath is non-zero. Is there a way to avoid the loop being
entered when the command has no output and avoid the need for this
check?
(btw, is there a good set of examples of using parameter expansion
flags? The zsh guide seemed a bit sparse in this area)
Thanks,
--- John
[-- Attachment #2: Type: text/html, Size: 6784 bytes --]
next reply other threads:[~2006-05-10 9:22 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2006-05-10 9:22 John Cooper [this message]
2006-05-10 17:28 ` Bart Schaefer
2006-05-11 9:59 John Cooper
2006-05-11 16:38 ` Bart Schaefer
2006-05-12 11:02 John Cooper
2006-05-12 14:45 ` Bart Schaefer
2006-05-15 9:01 John Cooper
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=DD74FBB8EE28D441903D56487861CD9D0971728B@lonpexch01.citrite.net \
--to=john.cooper@eu.citrix.com \
--cc=zsh-users@sunsite.dk \
/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).