# scripting: multiple values from file passing to command

**URL:** <https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310>\
**Category:** UNIX for Dummies Questions & Answers\
**Created:** [July 19, 2007, 8:53pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310 "2007-07-19T20:53:48Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![LisaS](https://community.unix.com/letter_avatar/lisas/32/6_22734026db12803ebb3e059622ac3534.png) [@LisaS](https://community.unix.com/u/LisaS)\
**Post date:** [July 19, 2007, 8:53pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/1 "2007-07-19T20:53:48Z")

</div>

one of my colleagues has this question.  
he has a command, C\_CMD which accepts 4 variables, $1 $2 $3 $4  
he wants to load up a file with multiple rows, one row per set of variables and then iteratively execute the command based on the content of the file.

example:  
at the command line you'd issue:  
C\_CMD A1 B1 C1 D1  
C\_CMD A2 B2 C2 D2  
C\_CMD A3 B3 C3 D3

but he wants to have FILE\_C with:  
A1 B1 C1 D1  
A2 B2 C2 D2  
A3 B3 C3 D3

and then process this in a script to iteratively invoke C\_CMD similar to how you would with a single variable like this  
for $file in `cat \path\FILE_D`  
do  
D\_CMD $file  
done

can you assist? I thought I saw something similar here a few days ago but now cannot find it.

Lisa

---

<div class="post-metadata">

**Author:** ![Shell\_Life](https://community.unix.com/user_avatar/community.unix.com/shell_life/32/521_2.png) [@Shell\_Life](https://community.unix.com/u/Shell_Life)\
**Post date:** [July 19, 2007, 9:08pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/2 "2007-07-19T21:08:14Z")

</div>

Lisa,  
You are almost there:

```nohighlight
while read mParms
do
  D_CMD $mParms
done < \path\FILE_D

```

---

<div class="post-metadata">

**Author:** ![LisaS](https://community.unix.com/letter_avatar/lisas/32/6_22734026db12803ebb3e059622ac3534.png) [@LisaS](https://community.unix.com/u/LisaS)\
**Post date:** [July 19, 2007, 9:55pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/3 "2007-07-19T21:55:54Z")

</div>

Shell\_Life  
I may be a little dense here - is that an answer for my multiple variable example or for my single variable example?  
you used my single var "names" and that's what is confusing me.  
I was asking how to script the C\_CMD $1 $2 $3 $4 example  
if your answer does that, please excuse my thickheadedness - I will try it when I can login again.

---

<div class="post-metadata">

**Author:** ![Shell\_Life](https://community.unix.com/user_avatar/community.unix.com/shell_life/32/521_2.png) [@Shell\_Life](https://community.unix.com/u/Shell_Life)\
**Post date:** [July 20, 2007, 10:29am UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/4 "2007-07-20T10:29:42Z")

</div>

Lisa,  
The single variable 'mParms' has all your parameters from each record  
in your file.

---

<div class="post-metadata">

**Author:** ![LisaS](https://community.unix.com/letter_avatar/lisas/32/6_22734026db12803ebb3e059622ac3534.png) [@LisaS](https://community.unix.com/u/LisaS)\
**Post date:** [July 20, 2007, 1:27pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/5 "2007-07-20T13:27:35Z")

</div>

yes, thank you - I could see that after I "slept on it"  
what if I changed it up and needed to be able to reference them separately like  
C\_CMD $1 | grep $2 | grep -v $3 | lp -d$4

would I have to just parse them out of the one variable or is there a differen techinque to use in that case

(not that I'd write that stmt but just example of piping and passing them)

---

<div class="post-metadata">

**Author:** ![Shell\_Life](https://community.unix.com/user_avatar/community.unix.com/shell_life/32/521_2.png) [@Shell\_Life](https://community.unix.com/u/Shell_Life)\
**Post date:** [July 20, 2007, 1:34pm UTC](https://community.unix.com/t/scripting-multiple-values-from-file-passing-to-command/173310/6 "2007-07-20T13:34:52Z")

</div>

If you want to access each individual variable:

```nohighlight
while read mVar1 mVar2 mVar3 mVar4
do
  echo "1 = "${mVar1}" 2 = "${mVar2}" 3 = "${mVar3}" 4 = "${mVar4}
done < input_file

```
