我从一个API中获得了以下数据:
[{"name":"***.com","id":"***-0a5864441f49","type":"NATIVE"},{"name":"***.de","id":"***-0a5864441f49","type":"NATIVE"},{"name":"***.com","id":"***-0a5864440f67","type":"NATIVE"},{"name":"***.de","id":"***-0a5864441314","type":"NATIVE"},{"name":"***.com","id":"***-0a586444968b","type":"NATIVE"},{"name":"***.de","id":"***-0a5864441314","type":"NATIVE"},{"name":"***.de","id":"***-0a5864441f49","type":"NATIVE"},{"name":"***.de","id":"***-0a5864441f49","type":"NATIVE"},{"name":"***.de","id":"***-0a58644406ac","type":"NATIVE"},{"name":"***.de","id":"***-0a58644435f4","type":"NATIVE"}]
字符串
我想创建一个菜单,像这样:
Choose one:
1. ***.com ***-0a5864441f49
2. ***.de ***-0a5864441f49
and so on...
型
然后我想进一步使用输入,在bash中,最有效的方法是什么?
我正在考虑一个数组,但我认为IFS不希望我使用},{
作为数组,对吗?
我试过使用IFS,但没有成功。
1条答案
按热度按时间0qx6xfy61#
您可以使用jq将输入转换为如下所示(参见playground):
字符串
在此基础上,您可以将此输出读取到数组中,然后使用
select
内置来呈现菜单:型
导致一个提示,
型