Sam
Sam

Reputation: 31

How to extract text from command result in bash script?

I am trying to write a script where I am executing

connmanctl services

it gives me:

A0 Wired ethernet_abcdefghijkl_cable

I want to extract ethernet_abcdefghijkl_cable and put it in a variable.

How can I do that?

I tried following so far but didn't work:

x="$(connmanctl services)"

echo "$x" | cut -d' ' -f 3

Upvotes: 0

Views: 766

Answers (1)

turquoise
turquoise

Reputation: 36

# store command output in an array
read -ra array < <(conmanctl services)

var=${array[2]}

no need to involve cut

Upvotes: 1

Related Questions