From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 25190 invoked by alias); 6 May 2015 20:50:50 -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: 20182 Received: (qmail 8842 invoked from network); 6 May 2015 20:50:38 -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,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.2 Message-ID: <554A7E95.7000306@gmx.com> Date: Wed, 06 May 2015 16:50:29 -0400 From: Eric Cook User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.6.0 MIME-Version: 1.0 To: zsh-users@zsh.org Subject: Re: new user questions and issues References: <67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com> In-Reply-To: <67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit X-Provags-ID: V03:K0:GIShQYuKx+RcUEotnqiZUHSkQ4ToxuVVSjHXZZmg0THdfLW/2fS Um4W18rkVto+5duIOutKD1kI7OUx39T4kahXQXV5kQvPrzCRERRKpd8UWm3VcjfW2fjgBBI pyayfhSUjiufCCTVEMTSaGIOcBNgOSVMTyNFk1D8hWNVRUI1mDlriBgwCvB8akzxEeNFyxN 9a+hgo6V80BvnMIJyrpww== X-UI-Out-Filterresults: notjunk:1; I can snipe the easier to explain ones. On 05/06/2015 01:37 PM, Kannan Varadhan wrote: > Issue #1: Programmatic Scripting, how to? > > I would like to do the following: > > for var in path infopath manpath cdpath ; do > typeset -agU $var > local capsvar > capsvar=$(echo $var | tr 'a-z' 'A-Z') > $var=( $(echo ${$capsvar} | sed 's/:/ /g') ) > done > > But this does not work, because ${$capsvar} gets me a zsh: bad substitution. > Is there any way to achieve this in zsh? > You can use the parameter expansion flag P. ''${(P)capsvar}'' With the exception of infopath, The arrays you are trying to define are already created and tied to the uppercase scalar parameters. Any change made to one is reflected in the other. echo by default interprets c string escapes, you can disable that with the -E option. You could avoid the command substitution with the parameter expansion flag U ''capsvar=${(U)var}'' to change the case of the value. $var=(...) is also an error. ''set -A $var element1 element2 ...'' will allow you to indirectly set arrays > Issue #2. Overridden local variables get echoed? > > ~ 5% cat lib/zsh/test2 9:55:52 > function test2 > print why is the previous value echoed when a local variable is 'overridden?' It actually happens when you use typeset, local, etc. on a parameter that is already defined. You can use the option TYPESET_SILENT option to silence it. from the typeset section of zshbuiltins(1): If the shell option TYPESET_SILENT is not set, for each remaining name that refers to a parameter that is set, the name and value of the parameter are printed in the form of an assignment. Nothing is printed for newly-created parameters, or when any attribute flags listed below are given along with the name. Using `+' instead of minus to introduce an attribute turns it off. Pretty sure #3 and #4 is due to how typeset creates a local parameters when used in a function. So typeset -U PATH create a new parameter without a value, with the -U attribute.