[Techtalk] line by line in bash

Hamster hamster at hamsternet.org
Sun Jun 8 21:23:41 EST 2003


I'm trying to achieve something in bash and not having much luck. Hoping
some one might know the answer!!

In essence it boils down to the ability to process a file one line at a

I have an existing bash script called "input", a portion of which contains
the entries:

# filename input

export int=blue
touch $file1
touch $file2
touch $file3


I am trying to write a second file that performs the following tasks:

For each line in "input" do 
	1. if the first word of the line is export, then execute that line
	2. if the first word is touch, then replace the word touch with rm
	and then execute that new command.
	3. if the line doesnt meet conditions 1 or 2 then just ignore it.

What I'm stuck with is being able to read the file one line at a time. I can
write the if statements and the sed statement, I just cant get the one line
at a time thing happening. Everything I try seems to process the file as one
long string of words rather than individual lines. 

I'm aware of a work around - simply use grep and sed and write the output to
a temp file, then execute that temp file. I'd prefer not to take this route
if possible.

I have a sneaky suspicion the solution might lie with awk, but I know as
much about awk as I do about the dietary requirements of the outer-mongolian
bat-winged frog.

I hope you can understand what I'm trying to say here, and I hope someone
has an answer!



More information about the Techtalk mailing list