Click to See Complete Forum and Search --> : little shell scripting


bsh152s
11-29-2001, 05:27 PM
I have a program that takes a parameter on the command line. I have a list of parameters that I want to run the program for in a file. Here's a little more info:

Paramfile

param1
param2
param3
...


I want a script that will simulate this:

myprogram param1
myprogram param2
myprogram param3
...


Right now, my script reads each line in Paramfile, writes all "myprogram paramx" to a new file, chmod u+x's the new file, and then runs the new executable. Surely there's a way to do this. I'm kinda new to scripting. Is there anyway to read from stdin in a shell script?

bwkaz
11-29-2001, 06:38 PM
for i in `cat paramfile` ; do
myprogram $i
done

There are probably a million other ways to do it, but this is the first way I thought of. The only possible problem is that the list of params have to all be one word (or single-quoted; maybe double-quoted would work also, but I don't know). The quotes around cat paramfile are backquotes, BTW -- the unshifted tilde key on most keyboards.

bsh152s
11-30-2001, 09:58 AM
Thanks. That worked great and I don't have to worry about creating a temporary file.