arrays - 从 cURL 结果访问项目列表

标签 arrays linux bash unix curl

如果你去这个网址:http://artii.herokuapp.com/fonts_list ,您将在列表中看到包含 417 个项目的列表。

我正在尝试创建一个变量来存储/访问这些列表。

我无法让它工作。

fontList=$(curl http://artii.herokuapp.com/fonts_list)
fontListCount=$(curl http://artii.herokuapp.com/fonts_list | wc -l)

for i in $(seq 1 $fontListCount);
do
    echo -e "I like this font --> " fontList[$i]
done

我不断得到

I like this font -->  fontList[1]
...
I like this font -->  fontList[417]

关于如何操作的任何提示?

最佳答案

假设结果实际上是每行一个字体名称,您可以使用一次调用 readarray:

readarray -t fontList < <(curl http://artii.herokuapp.com/fonts_list)

然后

for i in "${fontList[@]}"; do
  echo "I like this font --> $i"
done

关于arrays - 从 cURL 结果访问项目列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53307717/

相关文章:

c++ - 将列添加到二维数组

javascript array.slice().push() 未按预期工作

python - SciPy:使用 b 向量数组的逐元素非负最小二乘法

arrays - 如何在 bash 中设置数组元素的范围

c - 函数定义的 C 语法是什么

bash - 如何在 Awk 或 Sed 中将数学与正则表达式混合?

linux - 需要 bash 中选项卡的脚本解决方案

linux - 如何获得唯一的 `uid` ?

c++ - 为什么我得到 "error: ‘pthread_delay_np’ was not declared in this scope”?

mysql - 无法从外部 bash 脚本正确设置 MySQL 密码