1827243 Members
2353 Online
109716 Solutions
New Discussion

shell scripting

 
SOLVED
Go to solution
Mauro Gatti
Valued Contributor

shell scripting

Hi all, I must give to an internal procedure 4 parameters. This parameters are stored in a file.
I can't able to pass exactly these parameters to procedure.

The file eith parameters is like


alpha beta gamma delta
delta beta gamma alfa
beta sigma delta pi


the script is like:

#!/bin/sh
procedure ()
{

}

....

I must read the /tmp/file1.txt and run procdure like:
procedure alpha beta gamma delta

If I change IFS end i read file using:

for i in $(cat /tmp/file1.txt)
do
procedure $i
done

procedure get "alpha beta gamma delta" like a single parameter so into procedure $1 is alpha beta gamma delta and $2 $3 $4 are not set.


Any idea?

Thank You
Ubi maior, minor cessat!
2 REPLIES 2
Thierry Poels_1
Honored Contributor
Solution

Re: shell scripting

hi,

while read a b c d
do
yourproc $a $b $c $d
done < /tmp/file1.txt

good luck,
Thierry.
All unix flavours are exactly the same . . . . . . . . . . for end users anyway.
Donny Jekels
Respected Contributor

Re: shell scripting

My addition would be the same as the previous reply.

procedure() {
#
#
#
while read a b c d
do
other_proc ${a} ${b} ${c} ${d}
done < /tmp/file1.txt

}

off course you need to realize when you hit blank lines it will pass nothing at that time.

handle blank lines this way

procedure() {
#
cat /tmp/file1.txt | sed '/^$/d' | tee mydata
while read a b c d
do
my_other_proc ${a} $b} ${c} ${d}
done }

${a} is just a good programing habbit, to lock your variables. very usefull when the number of var's runs into the hundreds in the same script
peace
Donny
"Vision, is the art of seeing the invisible"