From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 4359 invoked by alias); 24 Apr 2013 18:40:05 -0000 Mailing-List: contact zsh-users-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Users List List-Post: List-Help: X-Seq: 17767 Received: (qmail 22080 invoked from network); 24 Apr 2013 18:40:02 -0000 X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on f.primenet.com.au X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 Received-SPF: pass (ns1.primenet.com.au: SPF record at _netblocks.google.com designates 209.85.128.177 as permitted sender) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:cc:content-type:content-transfer-encoding :x-gm-message-state; bh=xqDTFR0R3C/rWTEc1DOClncUNAswBAsgEFI/A7aRQdA=; b=BNpKlfQl/oGVzqEgock17PelC0/+cMNBHCRne+gihVlB/mIaENST10xfwA3EB/pE3Q mOdZNEY2pyAWSlfb7YO7QoN3TtEJHNgYeQWpIYgLt3/BPYG4UZcnEIWjeJCIMc2DK8J2 mK519wDIIElfp9htI7fVHkSZTDDR46J+BUkVyUTR1V9QfhkBk3Cg35vIcWZND4lx6ib5 +W4zQZWVSRs8+tQAayW4iqHiDpT1o4llDk5uujTu3zBJun/Obdpg0ki4C0UFVdO5CdBw j2iz0alGk249B/n4fJeUGnmDaFqxI/ZNGagmf12UvM1+/pCr2Zxh5KdzguUzLcOoDnZQ g0Og== X-Received: by 10.58.133.81 with SMTP id pa17mr18603278veb.37.1366828795787; Wed, 24 Apr 2013 11:39:55 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: From: thomasg Date: Wed, 24 Apr 2013 20:39:15 +0200 Message-ID: Subject: Re: How should I construct this? To: TJ Luoma Cc: Zsh-Users List Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Gm-Message-State: ALoCoQkDL6ZjNsx1VzByC15ybrGa2KMAIOhY/z0jO5pbcAx6LBC6BsBsUBIrn1uTB8fLx1tauk1o On Wed, Apr 24, 2013 at 8:16 PM, TJ Luoma wrote: > > I am trying to write a shell script which will help my computer > automatically join Wi-Fi networks. > > Each network needs to have an SSID (which may have spaces in it) and a > password (which may have spaces, punctuation, etc in it). > > I'm trying to figure out the best way to create this. > > I thought about trying to make an array or something like this where the > first 'column' would be the SSID and the 2nd column would be the password= s > > ALL_WIFI_NETWORKS=3D( > Home > 89382ashfa > Work > 0823u2j98dyumn > "Coffee House" "" > "Jenny's Wifi" 8675309 > ) > > > but then I need to be able to loop through $ALL_WIFI_NETWORKS using only > first column=E2=80=A6 something like this > > for SSID in {{{The First Arg in Each Line of $ALL_WIFI_NETWORKS}}} > do > echo "foo" > > done > > > where the part in {{{ and }}} indicates the part where I really don't kno= w > how to do what I want to do. > > It seems like there's got to be an easier / better way of doing this, but= I > can't figure out what it is, other than keeping two lists/arrays, one of = the > SSIDs, and one with the passwords, but that seems kludgey because I have = to > ask the user (whoever uses this script besides me) to put the SSIDs in > twice. > > TjL > What you want to use in a case like this are hashtables. Basically this is a special array type, defined like this: typeset -A ALL_WIFI_NETWORKS ALL_WIFI_NETWORKS=3D(name 'password' name2 'password2) You can then loop: for FOO in ${(k)ALL_WIFI_NETWORKS}; BAR Hope this helps, -- thomasg