Reading a variable line by line with while loop

NoOp glgxg at sbcglobal.net
Wed Dec 2 00:33:39 UTC 2009


On 12/01/2009 01:40 AM, Ray Parrish wrote:
> Hello,
> 
> I have been using while loops to read files in line by line when I want 
> to process things on a line oriented basis. Sometimes i have the set of 
> lines I want to read through already in a variable, and have to write 
> them to file before beginning to read line by line.
> 
> I was wondering if it is possible to read a variable line by line 
> somehow with a while loop? Would it possibly be faster than using a file 
> to read from?
> 
> I was thinking something along the lines of the following code might 
> work, but have not tested it yet.
> 
> while read ThisLine; do
>       # process each line
>       echo "$ThisLine"
> done < `echo "$Variable"`
> 
> Is this something that might work, and would it be more efficient than 
> writing to, and reading from a file? Is there some other way I've missed 
> to make it work?
> 
> Thanks for any help you can be.
> 
> Later, Ray Parrish
> 

I think that your continued learning experience with bash/command
line/scripts et al is educational (to some), but what/how are all of
these posts from you related to Ubuntu technical support, and more
specifically to this list?






More information about the ubuntu-users mailing list