庆典阵列新线IFS [英] bash array with new line as IFS

查看:113
本文介绍了庆典阵列新线IFS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是为什么没有产生结果的预期阵列

why is this not producing the expected array of results

IFS=$'\n'; read -a list <<< `lsblk` ; echo ${list[*]};

由于我需要添加到这个问题,我必须说,我有点困惑,为什么

Because I need to add to this question I have to say that I am a bit confused as to why

推荐答案

也许你需要使用 -l <​​/ STRONG>标记来获得设备列表,因为默认情况下的 lsblk 输出部分树视图。 (我没有lsblk,但我的lsusb所预期的结果):

Probably you need to use -l flag to get a list of devices, because by default lsblk output is in some tree view. (I don't have lsblk, but with lsusb I have expected result):

IFS=$'\n'; read -a list <<< `lsblk -l` ; echo ${list[*]};

您还可以试试下面阵列创造的更多的本机方式:

You can also try the more native way of array creation below:

list=( $(lsblk -l) ); echo ${list[*]}

这篇关于庆典阵列新线IFS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆