AWK also works well. It reads each line in a file, and provides each word in the line as a $ variable: example file contains: This is a line This is another line awk '{ print $1, $2, $3, $4 }' myfile This will print: This is a line This is another line On 9 May 2002 at 17:34, Graham Paul wrote:
Oops!
forgot the critical 'set $myparams' in the second approach - corrected below.
If say, your "parameters" file simply contains one line of 3 parameters:
arg1 arg2 arg3
and your script is (say) "myscript":
echo "\$1 = $1" echo "\$2 = $2" echo "\$3 = $3"
Then you can use this as:
cat parameters | xargs myscript
which will produce:
$1 = arg1 $2 = arg2 $3 = arg3
================================================================= However, if your "parameters" file contains more than one line:
arg1 arg2 arg3 nextarg1 nextarg2 nextarg3
and you want to execute 'myscript' twice, with 3 args each time you could do this instead:
while read myparams do set $myparams
echo "\$1 = $1" echo "\$2 = $2" echo "\$3 = $3" done < parameters
which would produce $1 = arg1 $2 = arg2 $3 = arg3 $1 = nextarg1 $2 = nextarg2 $3 = nextarg3
BTW - if your parameters file has more than one line, as above, the first approach would assign:
$1 = arg1 $2 = arg2 $3 = arg3 $4 = nextarg1 $5 = nextarg2 $6 = nextarg3
Take your pick. As always "there's more than one way to skin a cat"
Graham
-----Original Message----- From: Mark Hounschell [mailto:markh@compro.net] Sent: Thursday, May 09, 2002 5:06 PM To: suse-linux-e@suse.com Subject: [SLE] [OT] script help?
How can you use the contents of a file as command line parameters for a script? The file has 3 colums and each colume I want to be command line $1 $2 $3 respectivly for the script.
$script < file does not seem to work
Thanks and Regards Mark
-- To unsubscribe send e-mail to suse-linux-e-unsubscribe@suse.com For additional commands send e-mail to suse-linux-e-help@suse.com
Also check the archives at http://lists.suse.com
-- Jerry Feldman Portfolio Partner Engineering 508-467-4315 http://www.testdrive.compaq.com/linux/ Hewlett-Packard Company 200 Forest Street MRO1-3/F1 Marlboro, Ma. 01752