bug-bash
[Top][All Lists]
Advanced

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

Re: Taking input line by line from a config file in Bash


From: Bob Proulx
Subject: Re: Taking input line by line from a config file in Bash
Date: Wed, 2 Jan 2008 02:36:30 -0700
User-agent: Mutt/1.5.13 (2006-08-11)

Matthew_S wrote:
> 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`

The result of this will be split on words.  That is not what you want.

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

Yes.  Read would be quite a better way to do it.

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

That above makes no sense to me.

Try something more like this:

  while read line ; do
    echo "$line"
  done < config.txt

> But need to get the numbered input from by using cat -n on the config file,

Can you simply keep track of the line numbers yourself as you go along?

  lineno=0
  while read line ; do
    lineno=$(($lineno + 1))
    echo "$lineno: $line"
  done < config.txt

Bob




reply via email to

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