Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
new user questions and issues
- X-seq: zsh-users 20181
- From: Kannan Varadhan <kvaradhan3@xxxxxxxxx>
- To: zsh-users@xxxxxxx
- Subject: new user questions and issues
- Date: Wed, 6 May 2015 10:37:09 -0700
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=from:content-type:subject:message-id:date:to:mime-version; bh=ovBIyZG6bYmy/AcjJpNXW7ItVnHsCUlvNBNkjpLKG1k=; b=nWugX1yOSxeYFmVAMv6Fsi0ytueaXZc9Z/q1tD7M5ZGfKrR1ZWjbJaAEJlqo0fwTbh x7CVOpMUCoyhbc9Dm/n2IIOfvOxtpyV6B332skmYki1CheIXEmAmrEVQwSr4h5BuA5GY SLDTgrUErCNg7R+Gl4xYg85yBQ9rKS65Ce6/DgYSS9Gmo2MfA1J1uyyI9GnjfGjSyiJI PuBxmMz/0P8IC1e4tb7GVVglfew5jplGo/OdFb4vsQh9KYStyntyPbmyz2/OOQWVn5gH HeEhRekMfdVw2LkiQU9TTeUYT2E14DIuBDlknwqhbyW0DIDlrWJt2Jp5VgL3qKpgfWUe rgqw==
- List-help: <mailto:zsh-users-help@zsh.org>
- List-id: Zsh Users List <zsh-users.zsh.org>
- List-post: <mailto:zsh-users@zsh.org>
- Mailing-list: contact zsh-users-help@xxxxxxx; run by ezmlm
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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author