views:

72

answers:

2

Hi,

I want to pass a command to a shell script. This command is a grep command. While executing I am getting the following errors, please help:

myscript.sh "egrep 'ERROR|FATAL' \*20100428\*.log | grep -v aString"

myscript.sh is a simple script:

#!/bin/ksh

cd log

$1

the errors are:

egrep: can't open |
egrep: can't open grep
egrep: can't open -v
egrep: can't open aString

Error is because egrap sees |, grep, -v and aString as arguments.

+3  A: 

try this:

eval $1
frankc
Thanks a lot. It helped me.
raj_arni
A more correct version would be `eval "$1"`, which takes care of multiple space characters and prevents file globbing.
Roland Illig
+2  A: 

You can call sh -c $1 to invoke the first argument as commands in a new shell so that the shell special characters will be expanded.

maerics