From: Kannan Varadhan <kvaradhan3@gmail.com>
To: zsh-users@zsh.org
Subject: new user questions and issues
Date: Wed, 6 May 2015 10:37:09 -0700 [thread overview]
Message-ID: <67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com> (raw)
[-- Attachment #1: Type: text/plain, Size: 10816 bytes --]
Been a long time user of ksh, switching to try zsh.
My version:
~ 1% uname -a 0:26:57
Darwin KVARADHA-M-40SH 14.3.0 Darwin Kernel Version 14.3.0: Mon Mar 23 11:59:05 PDT 2015; root:xnu-2782.20.48~5/RELEASE_X86_64 x86_64
~ 2% echo $ZSH_VERSION 0:26:59
5.0.5
~ 3% echo $ZSH_PATCHLEVEL 0:27:18
zsh-5.0.5-0-g79abe00
~ 4% 0:27:23
Four Issues in this one email, sorry:
Issue #1: Programmatic Scripting, how to?
Issue #2. Overridden local variables get echoed?
Issue #3. Typeset -U from within a nested function behaves unpredictably (1)
Issue #4. Typeset -U from within a nested function really seems to get ignored (2)
Details below. Wondering if these are known, and how to either report or address.
Thanks,
Kannan
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?
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?'
local _t2
for _t2 in 0 1 2 ; do
local _t3
_t3=XXX__${_t2}__
done
}
set -x
~ 6% autoload test2 9:55:55
~ 7% test2 9:56:01
+test2:1> print why is the previous value echoed when a local variable is 'overridden?'
why is the previous value echoed when a local variable is overridden?
+test2:3> local _t2
+test2:4> _t2=0
+test2:5> local _t3
+test2:6> _t3=XXX__0__
+test2:4> _t2=1
+test2:5> local _t3
_t3=XXX__0__
+test2:6> _t3=XXX__1__
+test2:4> _t2=2
+test2:5> local _t3
_t3=XXX__1__
+test2:6> _t3=XXX__2__
~ 8% 9:56:03
Issue #3. Typeset -U from within a nested function behaves unpredictably (1)
Consider the following two functions: ap and _ap.
~ 1% cat lib/zsh/ap lib/zsh/_ap 10:11:21
function ap {
local _api
for _api in "$@" ; do
_ap "" PATH $_api/bin $_api/sbin
done
}
autoload _ap
function _ap {
local _shift _envar _enval _i
_shift=$1 ; shift
_envar=$1 ; shift
: '***' EXPECT FULL PATH VARIABLE BELOW '***'
_enval=$(eval echo \$$_envar)
}
# guarantee uniqueness
: PATH = $PATH
typeset -U PATH
~ 2% 10:11:27
~ 2% 10:11:29
~ 2% setopt KSH_AUTOLOAD 10:11:30
~ 3% autoload ap 10:11:39
~ 4% set -x 10:12:37
~ 5% ap x y 10:12:39
+-zsh:7> ap x y
+ap:7> autoload _ap
+ap:1> local _api
+ap:2> _api=x
+ap:3> _ap '' PATH x/bin x/sbin
+ap:9> : PATH '=' /Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+ap:10> typeset -U PATH
+_ap:1> local _shift _envar _enval _i
+_ap:2> _shift=''
+_ap:2> shift
+_ap:3> _envar=PATH
+_ap:3> shift
+_ap:4> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:5> _enval=+_ap:5> eval echo '$PATH'
+(eval):1> echo
+_ap:5> _enval=''
+ap:2> _api=y
+ap:3> _ap '' PATH y/bin y/sbin
+_ap:1> local _shift _envar _enval _i
+_ap:2> _shift=''
+_ap:2> shift
+_ap:3> _envar=PATH
+_ap:3> shift
+_ap:4> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:5> _enval=+_ap:5> eval echo '$PATH'
+(eval):1> echo /Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+_ap:5> _enval=/Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
~ 6% 10:12:4
If I remove the typeset -U PATH in _ap, as:
~ 1% cat lib/zsh/_ap 10:15:28
function _ap {
local _shift _envar _enval _i
_shift=$1 ; shift
_envar=$1 ; shift
: '***' EXPECT FULL PATH VARIABLE BELOW '***'
_enval=$(eval echo \$$_envar)
}
# guarantee uniqueness
: PATH = $PATH
: typeset -U PATH
~ 2% 10:15:35
~ 2% 10:15:36
~ 2% setopt KSH_AUTOLOAD 10:15:36
~ 3% autoload ap 10:15:40
~ 4% set -x 10:15:43
~ 5% ap x y 10:15:52
+-zsh:7> ap x y
+ap:7> autoload _ap
+ap:1> local _api
+ap:2> _api=x
+ap:3> _ap '' PATH x/bin x/sbin
+ap:9> : PATH '=' /Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+ap:10> : typeset -U PATH
+_ap:1> local _shift _envar _enval _i
+_ap:2> _shift=''
+_ap:2> shift
+_ap:3> _envar=PATH
+_ap:3> shift
+_ap:4> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:5> _enval=+_ap:5> eval echo '$PATH'
+(eval):1> echo /Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+_ap:5> _enval=/Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+ap:2> _api=y
+ap:3> _ap '' PATH y/bin y/sbin
+_ap:1> local _shift _envar _enval _i
+_ap:2> _shift=''
+_ap:2> shift
+_ap:3> _envar=PATH
+_ap:3> shift
+_ap:4> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:5> _enval=+_ap:5> eval echo '$PATH'
+(eval):1> echo /Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
+_ap:5> _enval=/Users/kvaradha/sbin:/Users/kvaradha/bin:/opt/local/sbin:/opt/local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin:./bin:./sbin:../bin:../sbin
~ 6% 10:15:53
Issue #4. Typeset -U from within a nested function really seems to get ignored (2)
Consider the same two functions: ap and _ap.
~ 1% typeset -U 10:30:44
~ 2% setopt KSH_AUTOLOAD 10:30:50
~ 3% autoload ap 10:30:55
~ 4% cat lib/zsh/_ap 10:30:57
function _ap {
local _shift _envar _enval _i
_shift=$1 ; shift
_envar=$1 ; shift
set -x
for _i in "$@" ; do
: '***' EXPECT FULL PATH VARIABLE BELOW '***'
_enval=$(eval echo \$$_envar)
export $_envar=$_i:$_enval
done
set +x
}
set -x
# guarantee uniqueness
: PATH = $PATH
typeset -U PATH
set +x
~ 5% ap x x x 10:31:01
+ap:15> : PATH '=' /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+ap:16> typeset -U PATH
+ap:17> set +x
+_ap:5> _i=x/bin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo
+_ap:7> _enval=''
+_ap:8> export 'PATH=x/bin:'
+_ap:5> _i=x/sbin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo x/bin:
+_ap:7> _enval=x/bin:
+_ap:8> export 'PATH=x/sbin:x/bin:'
+_ap:10> set +x
+_ap:5> _i=x/bin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo /usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:7> _enval=/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:8> export 'PATH=x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin'
+_ap:5> _i=x/sbin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:7> _enval=x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:8> export 'PATH=x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin'
+_ap:10> set +x
+_ap:5> _i=x/bin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:7> _enval=x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:8> export 'PATH=x/bin:x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin'
+_ap:5> _i=x/sbin
+_ap:6> : '***' EXPECT FULL PATH VARIABLE BELOW '***'
+_ap:7> _enval=+_ap:7> eval echo '$PATH'
+(eval):1> echo x/bin:x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:7> _enval=x/bin:x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
+_ap:8> export 'PATH=x/sbin:x/bin:x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin'
+_ap:10> set +x
~ 6% typeset -U 10:31:12
~ 7% echo $PATH 10:31:16
x/sbin:x/bin:x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
~ 8% typeset -U PATH 10:31:26
~ 9% echo $PATH 10:31:29
x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
~ 10% typeset -U 10:31:32
PATH=x/sbin:x/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
~ 11% 10:31:35
next reply other threads:[~2015-05-06 17:37 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-05-06 17:37 Kannan Varadhan [this message]
2015-05-06 20:50 ` Eric Cook
2015-05-07 21:46 ` Kannan Varadhan
2015-05-07 21:54 ` ZyX
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=67F1153E-5D3C-4D29-BDD0-1BB9C71FF55A@gmail.com \
--to=kvaradhan3@gmail.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).