for loop with multiple variables ?

I have a script which selects two 'sets' of system LVM device files from a tabular file 'mapfile' using awk :

LIVELV=`awk '{print($1)}' mapfile`
BCVLV=`awk '{print($3)}' mapfile`

I wanted to pass these 'sets' into an LVM command 'loop' along the lines of :

lvmerge $BCVLV $LIVELV

ie. for each device file in column 1 of the file 'mapfile' merge in the device in column 3 of the same line.

I have messed about for hours with a for loop but I don't think this will handle the two different sets of variables in the same statement ?

I am probably approaching this from completely the wrong angle.

Any advice would be gratefully received - scripting isn't my strong suit - but god knows I'm trying !

You need a loop that loops on the elements from column one. Inside that loop, you need a 2nd loop for the elements in column 3.

Try to code it using that approach.

Hi :slight_smile:

You can achieve this by the following while loop :-

cat mapfile | while read next
do
LIVELV=`echo $next | awk '{print($1)}'`
BCVLV=`echo $next | awk '{print($3)}'`
lvmerge $BCVLV $LIVELV
done

I would suggest :-

awk '{print $1, $3}' mapfile | while read LIVELV BCVLV
do
lvmerge $BCVLV $LIVELV
done