0

I'm trying to assign a variable with a value I get from grep, here's my code

a="i 
am
a
string
"
b="$a"|grep am
echo "$b"

I expect the result is am, but the result b is empty. But when I code echo "$a"|grep am directly, I get the right result. why and how can I assign the result to b?

ZeroChow
  • 422
  • 2
  • 5
  • 16

1 Answers1

1

Do it like this:-

**b=$(echo "$a"|grep am) **

Himanshu
  • 835
  • 1
  • 13
  • 22