Leo
Leo

Reputation: 133

Create grep command dynamic and run from variable

I am trying to create regex dynamicly and then run it, this is part of script

...
param="egrep $2 $1"
shift
shift
while [ $# -ne 0 ]
do
param="$param""|egrep $1"
shift
done
$param // here i get error
...

But echo for $param seems to me ok

.P F1 a b c // run script

egrep a F1| egrep b| egrep c

What should I do in order to run $param correctly?

Upvotes: 0

Views: 825

Answers (2)

jspcal
jspcal

Reputation: 51904

try: eval $cmd


Upvotes: 0

Paul Creasey
Paul Creasey

Reputation: 28834

try

eval $param

Upvotes: 3

Related Questions