fish - 鱼壳:如何将元素附加到数组
问题描述
我正在尝试将元素附加到数组中。
我尝试的是:
for i in (seq 10)
set children $children $line[$i]
end
但这并没有添加新元素。它创建一个包含所有孩子的单个变量,然后是一个空格和 $line[$i]。
解决方案
使用 fish 版本 2.7.1-1113-ge598cb23 (3.0 pre-alpha),您可以使用set -a
(append) 或set -p
(prepend)。
set -l array "tiny tim" bob
set -l children joe elias matt
echo $children
for i in (seq 2)
set -a children $array[$i]
end
echo $children
输出:
joe elias matt
joe elias matt tiny tim bob
您还可以使用适用于最新版本 fish 的 string 命令。
set -l array "tiny tim" bob
set -l children joe elias matt
echo $children
for i in (seq 2)
set children (string join " " $children $array[$i])
end
echo $children
输出:
joe elias matt
joe elias matt tiny tim bob
推荐阅读
- php - 主页上的 WooCommerce 产品类别图像和类别标题
- javascript - Google 跟踪代码管理器变量解析错误:应为主要表达式
- python - Pandas 上的 ValueError 和 Pandas 或 matplotlib.pyplot 上的 KeyError
- mysql - 当我在 mysql 中从 express 发出任何查询时如何修复错误 | LINUX Debian?
- c# - 在 sql server json 列中搜索并使用实体框架核心使用它
- excel - Excel中的标签排序,VBA语法问题
- python - Scrapy xpath 不起作用 - 仅与 css-selector 结合使用?
- mongodb - 不能在嵌套数组中使用 $slice
- mysql - 我正在尝试创建一个公式,用于使用使用 MYSQL 的触发器从现有列中减去一个值
- c++ - 使用 Qt 的包装类进行多个 get/post 调用