zsh:`declare-p`关联数组不打印值

zsh:`declare-p`关联数组不打印值,zsh,associative-array,Zsh,Associative Array,运行帮助排版显示: 注意上面写的是参数和值 如果有: % typeset -p ZPLGM typeset -A ZPLGM 注意:上面没有键值,但它们确实存在: % echo $ZPLGM[PLUGINS_DIR] /home/ravi/.config/zsh/.zplugin/plugins 为什么排版-p不能像我期望的那样工作 如何让typeset打印一条语句,该语句在执行时将重新创建数组 因为变量ZPLGM是用-H选项定义的 unset foo typeset -AH foo=([

运行帮助排版
显示:

注意上面写的是
参数和值

如果有:

% typeset -p ZPLGM 
typeset -A ZPLGM
注意:上面没有键值,但它们确实存在:

% echo $ZPLGM[PLUGINS_DIR]
/home/ravi/.config/zsh/.zplugin/plugins
  • 为什么
    排版-p
    不能像我期望的那样工作
  • 如何让
    typeset
    打印一条语句,该语句在执行时将重新创建数组

  • 因为变量
    ZPLGM
    是用
    -H
    选项定义的

    unset foo
    typeset -AH foo=([bar]=123)
    #         ^----here
    echo $foo[bar]
    typeset -p foo
    
    typeset
    有一个选项
    -H
    ,如手册所述:


    因为变量
    ZPLGM
    是用
    -H
    选项定义的

    unset foo
    typeset -AH foo=([bar]=123)
    #         ^----here
    echo $foo[bar]
    typeset -p foo
    
    typeset
    有一个选项
    -H
    ,如手册所述:


    您确定没有混淆使用两个shell zsh和bash吗?首先,zsh没有
    help
    命令,在
    oh my zsh
    中,
    help
    man
    的别名<代码>帮助排版
    将显示错误。第二,您可能在bash中运行
    typeset-pzplgm
    ,但在zsh中运行
    echo
    命令。@Feng它肯定是
    zsh
    。我将问题更新为
    run-help
    run-help是/usr/share/zsh/functions/Misc/run-help
    中的一个shell函数。这解析为
    less/usr/share/zsh/5.5.1/help/declare
    declare-A foo;foo[bar]=a;foo[baz]=b;在zsh 5.6.2中为我声明-p foo
    打印
    排版-A foo=([bar]=A[baz]=b)
    。你确定使用两个shell zsh和bash不会混淆吗?首先,zsh没有
    help
    命令,在
    oh my zsh
    中,
    help
    man
    的别名<代码>帮助排版将显示错误。第二,您可能在bash中运行
    typeset-pzplgm
    ,但在zsh中运行
    echo
    命令。@Feng它肯定是
    zsh
    。我将问题更新为
    run-help
    run-help是/usr/share/zsh/functions/Misc/run-help
    中的一个shell函数。这解析为
    less/usr/share/zsh/5.5.1/help/declare
    declare-A foo;foo[bar]=a;foo[baz]=b;声明-p foo
    打印
    排版-A foo=([bar]=A[baz]=b)
    在zsh 5.6.2中为我。
    123
    typeset -A foo
    
      -H     Hide  value:  specifies that typeset will not display the
             value of the parameter when listing parameters; the  dis-
             play for such parameters is always as if the `+' flag had
             been given.  Use of the parameter is  in  other  respects
             normal, and the option does not apply if the parameter is
             specified by name, or by  pattern  with  the  -m  option.
             This   is  on  by  default  for  the  parameters  in  the
             zsh/parameter and zsh/mapfile  modules.   Note,  however,
             that  unlike the -h flag this is also useful for non-spe-
             cial parameters.
    
    unset foo
    typeset -A foo=([bar]=123)
    echo $foo[bar]
    typeset -p foo
    
    123
    typeset -A foo=( [bar]=123 )