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

Re: How should I construct this?



On Wed, Apr 24, 2013 at 06:40:25PM -0400, TJ Luoma wrote:
> 
> 
> On 24 Apr 2013, at 15:50, Bart Schaefer wrote:
> 
> >In addition to Thomas's hashtables remarks, zsh "for" also supports
> >populating multiple variables each pass around the loop.
> >
> >So if you have an ordinary array like your example (BTW I hope those
> >aren't your real passwords) then you can do
> >
> >	for SSID WIFIPASS in $ALL_WIFI_NETWORKS
> >	do
> >		# Attempt to join network $SSID using $WIFIPASS
> >	done
> 
> The only drawback that I have found to this is that it ignores "" for
> empty passwords

The "@" flag is your friend (see "Parameter Expansion Flags" in 
zshexpn):

    typeset -a wifi
    wifi=( ... )
    for ssid pass in "${(@)wifi}"; do ...; done

Sorry for the all-lower-case examples -- I'm lazy.

Paul.

-- 
Paul Hoffman <nkuitse@xxxxxxxxxxx>



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