【问题标题】:Shell Bash declaring an arrayShell Bash 声明一个数组
【发布时间】:2014-02-02 18:26:00
【问题描述】:

我在 Bash 中声明数组时遇到了一些问题。

我正在尝试使用declare -A 道具

但它给了我一个错误,指出:

  declare -A: invalid option           
  declare: usage: declare [-afFirtx] [-p] [name[=value]] ...]

任何帮助将不胜感激,因为数组当前为 0。

我正在尝试创建一个存储键和值的数组。

【问题讨论】:

  • declare 是内置的 bash。您使用的是ksh 还是bash
  • 你为什么使用 -A ??
  • 您是否有机会使用 MacOS?
  • 我正在尝试使用 bash v3.00.16 创建一个存储键和值的数组

标签: arrays bash shell unix scripting


【解决方案1】:

关联数组使用declare -A 声明。索引数组使用declare -a 声明。

如果您需要前者,请检查您的 bash bash --version 版本,因为它们是在 bash 4.0 中引入的。

【讨论】:

    猜你喜欢
    • 2021-11-05
    • 2023-03-09
    • 2015-08-03
    • 1970-01-01
    • 2012-07-22
    • 1970-01-01
    • 2012-11-15
    • 1970-01-01
    • 2012-10-19
    相关资源
    最近更新 更多