People
In a bash script I am writing I have a for loop that uses the output from a grep command to provide the data for the loop ie.
Code:
for CGI_DIR in `grep -e "^ *ScriptAlias " /etc/apache/httpd.conf`; do
echo "CGI_DIR = ${CGI_DIR}"
done
Problem is that the output of this is:
Code:
CGI_DIR = ScriptAlias
CGI_DIR = /cgi-bin/
CGI_DIR = "/srv/www/cgi-bin"
CGI_DIR = ScriptAlias
CGI_DIR = /2nd-cgi-bin/
CGI_DIR = "/loc/of/sec/cgi/scripts"
What I would like is for the CGI_DIR variable to have the complete line so the output becomes:
Code:
CGI_DIR = ScriptAlias /cgi-bin/ "/srv/www/cgi-bin"
CGI_DIR = ScriptAlias /2nd-cgi-bin/ "/loc/of/sec/cgi/scripts"
I will then use a nested loop to deal with each section of the variable.
I have tried putting the grep command in " " eg.
Code:
for CGI_DIR in "`grep -e "^ *ScriptAlias " /etc/apache/httpd.conf`"; do
but then the output becomes:
Code:
CGI_DIR = ScriptAlias /cgi-bin/ "/srv/www/cgi-bin"
ScriptAlias /2nd-cgi-bin/ "/loc/of/sec/cgi/scripts"
This is a single line complete with a line break in the middle.
All documentation I have read says that grep outputs whole lines that match the criteria but I think bash then sees the spaces and chops it up.
Any thoughts on how to stop bash chopping up the grep output so I can deal with the whole line on each iteration?
3d