I have to initialize a script variable in a for loop with different values taken from a input file as following:

#!/bin/bash
VAR1=0
VAR2=0

exec < $1
while read line 
do
    #initialize VAR1 AND VAR2 taking the values from '$line' ($1 and $2)

    #and then
    echo $VAR1
    echo $VAR2

    #here do whatever with both variables...

done

How to initialize VAR1 with $1 and VAR2 with $2 ??

Thanks in advance!!

link|improve this question
feedback

2 Answers

up vote 2 down vote accepted

I assume your input file has 2 whitespace-delimited fields:

#!/bin/bash
exec < "$1"
while read VAR1 VAR2 
do
    echo $VAR1
    echo $VAR2
done
link|improve this answer
feedback
#!/bin/bash
VAR1=$1
VAR2=$2

exec < $1
while read line 
do
    #initialize VAR1 AND VAR2 taking the values from '$line' ($1 and $2)

    #and then
    echo $VAR1
    echo $VAR2

    #here do whatever with both variables...

done

PS: $0 is the script name.

link|improve this answer
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.