Bash loop using output of grep not working as needed
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 Code:
CGI_DIR = ScriptAlias Code:
CGI_DIR = ScriptAlias /cgi-bin/ "/srv/www/cgi-bin" I have tried putting the grep command in " " eg. Code:
for CGI_DIR in "`grep -e "^ *ScriptAlias " /etc/apache/httpd.conf`"; do Code:
CGI_DIR = ScriptAlias /cgi-bin/ "/srv/www/cgi-bin" 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 |
I believe the OP of this thread here - http://www.linuxquestions.org/questi...-good.-613980/ - is asking the same question.
Setting the IFS as chrism01 has suggested there, should suffice. |
I would opt for
Code:
while read CGI_DIR |
h/w
Cheers for the heads up. I did all sorts of searches before posting but who would have guessed what the thread was about by the title :( Anyways I tried the suggestion of the IFS and got the same output as if I had used the " " around the grep command. I then looked at the suggestion of using the read command and the following looks like it might do what I am after: Code:
while read line Again thanks for the tip. 3d |
colucix
Snap (almost) :) Cheers 3d |
Quote:
use awk Code:
# awk '/ScriptAlias/' file Code:
#!/bin/sh |
ghostdog74
Cheers for the response. I have the script working with the read command but I will keep the awk syntax in mind for future. Cheers 3d |
Quote:
Code:
while read line |
All times are GMT -5. The time now is 11:52 PM. |