How to Pipe into Command Stored in Bash Variable

bashgreppipevariables

I enter two command in bash:

  1. $export g='grep "something"'
  2. $echo "something and another thing" | $g

But it doesn't work.

I want the second command to be evaluated by bash as : echo "something and another thing" | grep "something"

What should I do for that?

Best Answer

use an alias.

alias g='grep "something"'
echo "something and another thing" | g