Command: grep -i -n "rule" *.err *.log | grep -v "SP_RULE"
The above command when run gives me two -three lines of output.
Now I am storing the result of the grep command
ie,
ruleerrors=`grep -i -n "rule" *.err *.log | grep -v "SP_RULE"`
Now when I echo the value of ruleerrors, I am getting a large result similar to result of �ls� command along with the actual desired output.
grep returned multiple rows and the output is redirected to a variable then
-will it be saved in a single line (with hidden characters)? or in multiple lines ?
Could you help me if I am missing some thing from your message?
you said "Add double quotes around the variable name to avoid wildcard expansion"
The value is saved with newlines and everything. echoing it back without quoting will flatten any whitespace to single spaces. (This is a feature of the shell and its quoting mechanisms, not of echo.) To make sure you see the real actual value, examine the variable with set.
sh$ var=`perl -e 'print "Output\nwith\ \ \ spaces\t\ \nand newlines\n"'`
sh$ echo $var
Output with spaces and newlines
sh$ echo "$var"
Output
with spaces
and newlines
sh$ set | grep var=
var=$'Output\nwith spaces\t \nand newlines'
This is with bash; output will probably be slightly different with other shells.
Notice that the final trailing newline is chomped off by the shell.