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

Re: How should I construct this?





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

# INPUT

	ALL_WIFI_NETWORKS=(
		"Home"				"89382ashfa"
		"Work"				"0823u2j98dyumn"
		"Coffee House"		""
		"Jenny's Wifi"		"8675309"
	)

	for SSID WIFIPASS in $ALL_WIFI_NETWORKS
	do
			echo "SSID: ${SSID}\tPass: ${WIFIPASS}\n"
	done

# RESULTS

	SSID: Home	Pass: 89382ashfa

	SSID: Work	Pass: 0823u2j98dyumn

	SSID: Coffee House	Pass: Jenny's Wifi

	SSID: 8675309	Pass:



So I'll just use a single character to represent empty passwords, such as


	ALL_WIFI_NETWORKS=(
		"Home"				"89382ashfa"
		"Work"				"0823u2j98dyumn"
		"Coffee House"		"-"
		"Jenny's Wifi"		"8675309"
	)

	for SSID WIFIPASS in $ALL_WIFI_NETWORKS
	do
			echo "SSID: ${SSID}\tPass: ${WIFIPASS}\n"
	done

and then check for a password equal to - before sending the command.

TjL



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