【问题标题】:Declaring arrays in ZSH在 ZSH 中声明数组
【发布时间】:2015-05-15 22:33:43
【问题描述】:

我在将 shell 脚本转换为 zsh 时遇到问题。我定义了以下数组,但它抛出错误unknown file attribute: \n。 (我正在将一个 dotfiles 存储库转换为我的 zsh)

declare -r -a FILES_TO_SOURCE=(
    "bash_aliases"
    "bash_exports"
    "bash_functions"
    "bash_options"
    "bash_prompt"
    "bash.local"
)

【问题讨论】:

    标签: shell command-line zsh


    【解决方案1】:

    来自man zshbuiltins,在typeset 的条目下(其中declare 是同义词):

    对于每个 name=value 赋值,参数 name 设置为 value。请注意,数组目前不能 在排版表达式中赋值,只能是标量和整数。

    试试这个:

    declare -a FILES_TO_SOURCE
    FILES_TO_SOURCE=(
        "bash_aliases"
        "bash_exports"
        "bash_functions"
        "bash_options"
        "bash_prompt"
        "bash.local"
    )
    declare -r FILES_TO_SOURCE
    

    话虽如此,为了兼容性,文件列表很可能必须在此处更改(假设您在那些似乎可能的文件中使用了 bash-isms)。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2020-10-24
      • 1970-01-01
      • 2016-12-09
      • 1970-01-01
      • 2017-04-07
      • 1970-01-01
      • 2015-05-29
      相关资源
      最近更新 更多