I am recursively searching for the occurrence of php scripts being called from other files using the following script.
find . -exec grep -Hn $1 {} \; | grep -v ^Binary;
Works great! Now, I need the returned results to determine the action to be taken next.
r=$(find . -exec grep -Hn $str {} \; | grep -v ^Binary;)
if [ -z "$r" ];
then
Do this
else
Do something else
fi
PROBLEM: By it's self the find script returns the results, each on a new line.
./path/to/file.php
./path/to/another_file.php
./path/to/third_file.php
However, when assigning the output to the $r variable, the newline character is not preserved and the results are printed on one line making it difficult to read.
./path/to/file.php ./path/to/file.php ./path/to/third_file.php
How do I preserve the newline character while assigning the output into a variable?
echo $r
orecho "$r"
? If you're sayingecho $r
, then the newlines are getting stripped on output.