From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 3226 invoked by alias); 23 Jan 2015 17:15:16 -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: 19772 Received: (qmail 26083 invoked from network); 23 Jan 2015 17:15:14 -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=-1.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 X-CMAE-Score: 0 X-CMAE-Analysis: v=2.1 cv=CoYIqc8G c=1 sm=1 tr=0 a=FT8er97JFeGWzr5TCOCO5w==:117 a=kj9zAlcOel0A:10 a=q2GGsy2AAAAA:8 a=oR5dmqMzAAAA:8 a=-9mUelKeXuEA:10 a=YNv0rlydsVwA:10 a=XgkoljilhfJTG_UUlC8A:9 a=CjuIK1q_8ugA:10 From: Bart Schaefer Message-id: <150123091511.ZM1667@torch.brasslantern.com> Date: Fri, 23 Jan 2015 09:15:11 -0800 In-reply-to: Comments: In reply to TJ Luoma "zparseopts help" (Jan 23, 10:39am) References: X-Mailer: OpenZMail Classic (0.9.2 24April2005) To: Zsh-Users List Subject: Re: zparseopts help MIME-version: 1.0 Content-type: text/plain; charset=us-ascii On Jan 23, 10:39am, TJ Luoma wrote: } } I took a look through the `man` entry, but 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. Not uncommon ... if we could find some volunteers to write more examples for the manual, that would be nice. } zparseopts -D -E -A MyVariableNameHere -- a b -orange -grape -apple } } Questions: } } 1. Is there a way to combine the -a and --apple statements into one? Yes, that's what zparseopts -M is for. With -M, "-apple=a" means to store anything you find for "--apple" in the location for "-a" instead. zparseopts -M -D -E -A MyVariableNameHere -- a b -orange -grape -apple=a } 2. Are a series of 'if' statements the best way to handle these sorts of } options? If you're using "-A MyVariableNameHere" then you should be able to do # Cycle through the keys of the associative array for myOption in "${(k@)MyVariableNameHere}" do case "$myOption" in ... esac done } ps - if anyone knows of a good place for zparseopts examples, please let me } know. Google was not very much help. The majority of uses of zparseopts are to interpret the options of some *other* command, do some manipuation on them, and then construct a call to that other command. I.e., for writing a wrapper function around some other complicated command. So you won't find very many good examples of doing something with everything that zparseopts parsed. The only comprehensive example in the zsh distribution is the "zargs" function, but it uses "-a array" instead of "-A hash" so the handling of the parsed options might be too confusing for an introduction. I wish I had a better suggestion.