zsh-users
 help / color / mirror / code / Atom feed
From: ZyX <kp-pav@yandex.ru>
To: Kannan Varadhan <kvaradhan3@gmail.com>, Eric Cook <llua@gmx.com>
Cc: "zsh-users@zsh.org" <zsh-users@zsh.org>
Subject: Re: new user questions and issues
Date: Fri, 08 May 2015 00:54:35 +0300	[thread overview]
Message-ID: <2934101431035675@web27m.yandex.ru> (raw)
In-Reply-To: <5427ED9E-C5F2-472F-B6B7-662962830ED8@gmail.com>

About local: instead of setting an option it looks like you can use

    typeset +g _t3

(`typeset +g`, `typeset` and `local` are almost equivalent, but typeset without any flags listed in documentation exhibits the same behaviour as `local`). Specifically in the example you can use

    local _t3=XXX__${_t2}__

: when there is an assignment `local` will not print previous value.



08.05.2015, 00:47, "Kannan Varadhan" <kvaradhan3@gmail.com>:
> Thank you Eric.
>
> I had worked out other ways of achieving #1, just wanted to learn if there was a good way to do it.
>
> The others, I get.
>
> Thanks,
>
> Kannan
>>  On May 6, 2015, at 1:50 PM, Eric Cook <llua@gmx.com> wrote:
>>
>>  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.


  reply	other threads:[~2015-05-07 22:05 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-05-06 17:37 Kannan Varadhan
2015-05-06 20:50 ` Eric Cook
2015-05-07 21:46   ` Kannan Varadhan
2015-05-07 21:54     ` ZyX [this message]
2015-05-11  5:02 ` Bart Schaefer
2015-05-11 17:43   ` Kannan Varadhan
2015-05-12  2:43     ` Bart Schaefer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2934101431035675@web27m.yandex.ru \
    --to=kp-pav@yandex.ru \
    --cc=kvaradhan3@gmail.com \
    --cc=llua@gmx.com \
    --cc=zsh-users@zsh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).