0

As the following example:

#! /bin/bash

usbId=$(lsusb | cut -d ' ' -f 6)

the $usbId is a multi line string which contains all usb devices on my computer. And I want to pick-up one of these line. Just like:

echo ${usbId[1]} # Don't work

In what way I can do that?

Thanks!

Koen
  • 311
  • 2
  • 11
  • `usbId="$(lsusb | cut -d ' ' -f 6)"; echo "$usbId"` – Inian Aug 14 '19 at 08:49
  • `usbId=$(lsusb | while read a b c d e id rest; do echo $id; done | sed -n -e "2p")` if you want just the second id – Laurent G Aug 14 '19 at 09:54
  • IFS=$'\r\n' GLOBIGNORE='*' command eval 'array=($(lsusb))';echo "${array[1]}"|awk '{print $6}' This one liner will push all the usb data into an array called array and give you value number 1 from the array ; for other values change the number value in the array – AAber Aug 14 '19 at 11:34
  • @Inian, thanks for reply. I just want one line of the multi line string. – Koen Aug 15 '19 at 02:12

0 Answers0