I am trying to grab results from lshw and add them to a a bash array so I can create a new string. I am using
lshw -class disk |egrep -A 7 .'-d' |grep 'product' |cut -b 17-
the output looks like this
Samsung SSD 850
Samsung SSD 840
ST8000AS0002-1NA
ST8000AS0002-1NA
Samsung SSD 870
Samsung SSD 870
ST8000VN0022-2EL
Flash Drive FIT
Flash Drive FIT
ST8000AS0002-1NA
ST8000VN0022-2EL
Samsung SSD 870
Samsung SSD 870
ST8000VN004-2M21
I tried to add this output to a bash array but each line with words separated by a space becomes an element in the array. You can also see the results from this command
for w in $(lshw -class disk |egrep -A 7 .'-d' |grep 'product' |cut -b 17-); do printf "$w \n" ;done
output
Samsung
SSD
850
Samsung
SSD
840
ST8000AS0002-1NA
ST8000AS0002-1NA
Samsung
SSD
870
Samsung
SSD
870
ST8000VN0022-2EL
Flash
Drive
FIT
Flash
Drive
FIT
ST8000AS0002-1NA
ST8000VN0022-2EL
Samsung
SSD
870
Samsung
SSD
870
ST8000VN004-2M21
How can I can I keep space separated lines as one one string?
lshw- I'd suggest using its JSON output format withjqto extract the information, something likelshw -class disk -json | jq -r 'select(.id == "disk") | .product'