-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

Ronak Patel
  • 3,819
  • 1
  • 16
  • 29
Efrat Levy
  • 109
  • 3
  • 6

2 Answers2

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

chepner
  • 497,756
  • 71
  • 530
  • 681
Shruti Paliwal
  • 175
  • 1
  • 9
0

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

OUTPUT=abc
PHYSIN="lalala ghi"

VETH_NAME=${PHYSIN%% *}
chepner
  • 497,756
  • 71
  • 530
  • 681
  • I notice this is basically identical to your answer to http://stackoverflow.com/questions/15148796/bash-get-string-after-character - perhaps you'd like to review [the Stack Overflow `bash` tag wiki](//stackoverflow.com/tags/bash/info) 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. – tripleee Aug 04 '16 at 13:54
  • 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. – chepner Aug 04 '16 at 13:59
  • 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! – tripleee Aug 04 '16 at 14:01