Help with strings in Bourne shell

James Logan III logan at vsedev.VSE.COM
Tue Apr 25 06:27:47 AEST 1989


In article <10166 at orstcs.CS.ORST.EDU> rudolf at oce.orst.edu (Jim Rudolf) writes:
# If I have a Bourne script called 'foo' and I call it with the arguments:
#    foo "color = red" "size = big"
# then from within foo they will be read as:
#    $1 = "color = red"
#    $2 = "size = big"
# However, I want to read from stdin (or maybe a redirected pipe), and I
# can't get it to work no matter what strange combination of quotes I use!
# I would like to do something like:
#    read args
#    for i in $args
#    .
#    .
# so I can process each string in turn.

If I have interpreted your question correctly, you want to read
the lines 

	color = red
	size = big

into your script and have each line read into a variable.


To do this, use the construct:

	while read DEFINITION; do
		echo "$DEFINITION";
		.
		.
		.
	done;


BTW, you can also read from a specific file by redirecting the
input to the read command like this:

	INPUTFILE="some_file";

	while read DEFINITION <$INPUTFILE; do
		echo "$DEFINITION";
		.
		.
		.
	done;


			-Jim

-- 
Jim Logan                           logan at vsedev.vse.com
VSE Software Development Lab        uucp:  ..!uunet!vsedev!logan
(703) 329-4654                      inet:  logan%vsedev.vse.com at uunet.uu.net



More information about the Comp.unix.questions mailing list