From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 22788 invoked by alias); 23 Jan 2015 15:40:18 -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: 19770 Received: (qmail 14196 invoked from network); 23 Jan 2015 15:40:17 -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.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW autolearn=ham version=3.3.2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:from:date:message-id:subject:to:content-type; bh=fJmrFjePoJHAYwpTbsm4p/viVvIUTn3qYiTbPguexAo=; b=HLS+Ny0w1yudSd7LM7zyMqTvZ9ZaE2IHeKnWRdh1lNhuNMti1HjRHBoGzNZT9rOER4 nr+Zfis094Sgdc50sSQYuYMIZcl5BXdRiHUu3m6C+g8l6bU6OqUKec6ZBbRtygWbBf5C B5KT2bEsnOBRTeLxrfFe5HPqRGhVukiBauOLJ/qck7C1Uv+K7hN+eHOKp+kMyPlwu1X9 44tK5MadAn2HZ3x3AKiNwcctF3IdLid3k/ZPP6OBxLA2OahjjHw7MJnyrZiiTWL5l1C9 FnpLB2Qq8MbYGRT/rIqSfA5vWp8iMxiKqVaErGh55T75xiA2BmeikOMu1b1AwY3YnyRo qwsA== X-Received: by 10.107.12.196 with SMTP id 65mr4439158iom.71.1422027612931; Fri, 23 Jan 2015 07:40:12 -0800 (PST) MIME-Version: 1.0 From: TJ Luoma Date: Fri, 23 Jan 2015 10:39:32 -0500 Message-ID: Subject: zparseopts help To: Zsh-Users List Content-Type: multipart/alternative; boundary=001a113f8fd2bacdf4050d539a05 --001a113f8fd2bacdf4050d539a05 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable As I've mentioned before, I have been using zsh forever but feel like I missed out on learning about 97% of what it can do. For example, today I learned about zparseopts. (Feel free to mock.) I took a look through the `man` entry, but=E2=80=A6 I don't know what it is= about my brain, but I can read and re-read man pages and still fail to understand what it is saying. I do much better with examples. I did some googling and found http://emg-2.blogspot.com/2008/01/zsh-unique-features.html and once I had that I could go back and look at the `man` page to understand what it was doing. So here is my first attempt at using `zparseopts`: zparseopts -D -E -A MyVariableNameHere -- a b -orange -grape -apple if (( ${+MyVariableNameHere[-a]} )); then echo "Apple"; fi if (( ${+MyVariableNameHere[--apple]} )); then echo "Apple"; fi if (( ${+MyVariableNameHere[-b]} )); then echo "Banana"; fi if (( ${+MyVariableNameHere[--orange]} )); then echo "orange"; fi if (( ${+MyVariableNameHere[--grape]} )); then echo "grape"; fi Questions: 1. Is there a way to combine the -a and --apple statements into one? 2. Are a series of 'if' statements the best way to handle these sorts of options? What I have been doing is something like this: for MyVariableNameHere in "$@" do case "$MyVariableNameHere" in -a|--apple) echo "Apple" shift ;; -b|--banana) echo "Banana" shift ;; esac done but that has the disadvantage of not being able to parse "-ab" as two separate arguments. OTOH it's very readable and I don't have to worry about very many chances of missing a closing bracket or brace! TjL ps - if anyone knows of a good place for zparseopts examples, please let me know. Google was not very much help. --001a113f8fd2bacdf4050d539a05--