bug-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Taking input line by line from a config file in Bash


From: Matthew_S
Subject: Taking input line by line from a config file in Bash
Date: Wed, 2 Jan 2008 01:25:32 -0800 (PST)

Hi all and firstly… Happy New Year!

It wouldn’t be a New Year without a New Problem though ;-)

I’m trying to create a script that will take the input of a config file line
by line.  Unfortunately, what seems to be happening is that it is taking it
though word by word instead?

For arguments sake I’ve put ‘I want this whole line on one line’ into the
config file and the script looks like this;

for i in `cat config.txt`
        do echo $i
        echo >> $RESULTS
        echo $i >> $RESULTS
        $i
        [ $? == 0 ] && echo "PASSED" >> $RESULTS || echo "FAILED" >>
$RESULTS
        Done

And here are the results;

I
./filesystem_test.sh: line 12: I: command not found
want
./filesystem_test.sh: line 12: want: command not found
this
./filesystem_test.sh: line 12: this: command not found
whole
./filesystem_test.sh: line 12: whole: command not found
line
./filesystem_test.sh: line 12: line: command not found
on
./filesystem_test.sh: line 12: on: command not found
one
./filesystem_test.sh: line 12: one: command not found
line
./filesystem_test.sh: line 12: line: command not found

It’s been suggested that I try read and so I have this;

File=./config.txt

{
read line
        echo $i
        echo >> $RESULTS
        echo $i >> $RESULTS
        $i
        [ $? == 0 ] && echo "PASSED" >> $RESULTS || echo "FAILED" >>
$RESULTS
} < $File

But need to get the numbered input from by using cat -n on the config file,
but the space delimiter in cut doesn’t seem to allow me to select only the
numbers?  Which means I can’t run something like;

for i in `cat -n config.txt | cut -d' ' -f1
        do read line $i
        etc…

Any help or guidance would be greatly appreciated.

Many thanks.

Matthew.
-- 
View this message in context: 
http://www.nabble.com/Taking-input-line-by-line-from-a-config-file-in-Bash-tp14575394p14575394.html
Sent from the Gnu - Bash mailing list archive at Nabble.com.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]