-2

I have variable $OUTPUT=abc PHYSIN=lalala ghi

How can I extract the value of PHYSIN into another new variable called VETH_NAME, in other words, I'd like VETH_NAME to be lalala

How can I do so using bash commands?

Thanks

1
  • Please format your question and show a minimal reproducible example so it is clear what you are asking here. Commented Aug 4, 2016 at 11:00

2 Answers 2

1

Assuming this is what you are saying :

OUTPUT="abc"
PHYSIN="lalala ghi"


VETH_NAME=$(echo "$PHYSIN" | cut -d" " -f1)

finally :

echo $VETH_NAME

lalala

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

Comments

0

Use parameter expansion with the %% operator, which drops the longest matching suffix from the expansion.

OUTPUT=abc
PHYSIN="lalala ghi"

VETH_NAME=${PHYSIN%% *}

3 Comments

I notice this is basically identical to your answer to stackoverflow.com/questions/15148796/… - perhaps you'd like to review the Stack Overflow bash tag wiki where we have collected a number of common FAQs. Obviously, if you'd like to help us maintain, organize, and develop this resource, you're most welcome! Thanks in advance.
I have tried; I link to some of the questions frequently, but don't pretend to memorize all the links on that page. Questions like this are far faster to whip out an answer than to search for a duplicate.
Yeah, it's a struggle. But thanks for following up; just wanted to make sure you are aware. There's a link to a chat room down at the end if you'd like to participate at some later time. Cheers!

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.