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,