OT: shell scripting problem

Steven W. Orr steveo at syslang.net
Wed May 18 17:52:14 UTC 2005


On Wednesday, May 18th 2005 at 10:22 -0700, quoth Rick Stevens:

=>Alexander Dalloz wrote:
=>> Am Mi, den 18.05.2005 schrieb linux.whiz at gmail.com um 0:55:
=>> 
=>> 
=>> > My brain is fried.  I know there is a simple answer to this but I'm
=>> > drawing a blank.  I want to run a script against the contents of a
=>> > text file.  The text file is just my users' first name, middle initial
=>> > and last name like this:
=>> > 
=>> > John A Smith
=>> > Mary P James
=>> > Sally R Jones
=>> > Fred Q Davis
=>> > 
=>> > What I want to do is for each user in this file, run a script.  I
=>> > tried to do this:
=>> > 
=>> > for i in `cat textfile`; do
=>> >  myscript.sh $i
=>> > done
=>> > 
=>> > I expect this to run like this:
=>> > 
=>> > myscript.sh John A Smith
=>> > myscript.sh Mary P James
=>> > myscript.sh Sally R Jones
=>> > myscript.sh Fred Q Davis
=>
=>I have another solution.  Change the script (let's call it "fred"):
=>
=>	while read i; do
=>	    myscript.sh $i
=>	done
=>
=>Then "cat textfile | ./fred" would accomplish the same thing.

Why in the Wide World of Sports do people do stuff like that?

./fred < textfile

No pipe, no extra process, no fuss.



-- 
echo "Steven W. Orr" | cat | less | more | most | xargs echo




More information about the users mailing list