Hi,
I have written the following shell script -
Error_String="error"
var1="| grep -v note1 | grep -v note2"
grep -i $Error_String /users/mqm/Pwork/Err/*.out $var1
The above script gives error saying "grep: can't open |
grep: can't open grep
grep: can't open -v" etc
In my program note1 and note2 strings are dynamically generated, so I cannot hardcode those in grep command.
Could anyone please help me to resolve this problem
Thanks in advance,
Prasanna
First of all, say excatily you are trying to acomplish.
var1 is supposed to contain the string "| grep -v note1 | grep -v note2" or the result of grep command?
You need to change note1 and note2 to $note1 and $note2. I would do it like this:
The reason why $var1 didn't work was because the shell automatically quoted it when it expanded the variable. So the command line actually looked like this:Code:result=$(grep -i $Error_String /users/mqm/Pwork/Err/*.out | grep -v $note1 | grep -v $note2)
grep -i $Error_String /users/mqm/Pwork/Err/*.out "| grep -v note1 | grep -v note2"
In addition to grepping every .out file, grep would have also tried to open a file called | grep -v note1 | grep -v note2, which of course doesn't exist.
sudo rm -rf /
There are currently 2 users browsing this thread. (0 members and 2 guests)
Bookmarks