Reading a variable line by line with while loop
Ray Parrish
crp at cmc.net
Wed Dec 2 01:55:19 UTC 2009
NoOp wrote:
> 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?
>
Damned if I know... I just figured this was a good forum to discuss bash
scripting since it is such an inherent part of Ubuntu that without
learning it you really cannot administer your machine as easily.
Currently I'm working on a bash history manager, and bash based all
around bash manager. When I'm done with it, it will be able to
interactively run bash commands either from the history list, or from
being typed in, and will output all the normal output any good or bad
command would put out.
It will also provide a GUI interface to the settings in ~/.bashrc, and
if I can figure out how to do it, will be able to run down through the
bash history, testing each command for success, or failure, and weeding
out the lines that are not syntactically correct by parsing the stderr
output for clues.
I do have a tech support question that I'll leave for another thread,
but it is a request for a bash command to find the script responsible
for attempting to start my firewall a second time during boot up causing
a "Fail" message because it is already started. 8-) Got a one liner that
covers discovering which scripts actually run the command on start up?
Later, Ray Parrish
--
The Future of Technology.
http://www.rayslinks.com/The%20Future%20of%20Technology.html
Ray's Links, a variety of links to usefull things, and articles by Ray.
http://www.rayslinks.com
Writings of "The" Schizophrenic, what it's like to be a schizo, and other
things, including my poetry.
http://www.writingsoftheschizophrenic.com
More information about the ubuntu-users
mailing list