【问题标题】:Work around for multidimensional arrays in bash?在 bash 中解决多维数组?
【发布时间】:2015-05-09 06:37:29
【问题描述】:

我目前不理解 bash *nix 中的数组。我主要使用 php。我一直在努力理解如何循环遍历多维数组。从一些基础研究中,我看到 bash 不处理多维数组。有解决办法吗?如何将以下 php 复制到 bash?

PHP 示例

$social_media = array( array( 'seconds' => 15, 'social' => 'Instagram'  ), array( 'seconds' => 7, 'social' => 'Vine'  ), array( 'seconds' => 10, 'social' => 'Snapchat'  ) );

foreach ($social_media as $value) {
    echo "{$value['social']} allows for videos to be {$value['seconds']} seconds long.</br>\n";
}

【问题讨论】:

标签: linux bash unix


【解决方案1】:

Bash 是一个命令处理器。编程语言基本上是用于执行命令并返回输出作为文本。然后可以将此输出作为输入传递给其他命令。

它不支持复杂的数据结构。在这个意义上是非常有限的。它从未打算运行复杂的逻辑,而是为简单的自动化而设计的。

【讨论】:

  • bash 确实支持数组。
  • 澄清一下,bash 数组旨在提供第二级引用 (args=("first arg" "second arg"); someTwoArgCommand "${args[@]}"),而不是作为复杂数据结构的构建块。
猜你喜欢
  • 2012-06-29
  • 1970-01-01
  • 2011-09-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-17
  • 2014-06-21
  • 2015-04-19
相关资源
最近更新 更多