0

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
3
  • 2
    what does your cut command return ? Its working for me, perhaps you may want to append 2>&1 to connmanctl command. Its possible that its printing to stderr ,although I am not sure. Commented May 7, 2019 at 16:46
  • 1
    It is working for me too. Commented May 7, 2019 at 16:46
  • @PS. I would just get empty return. Commented May 7, 2019 at 16:59

1 Answer 1

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

var=${array[2]}

no need to involve cut

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.