For loop returning more values

Hi All,

Thanks all of you for the help you provide to me. Well, I have one more problem, where I am trying to pull file system information in the loop and display the filesystem percentege. I am using following code to achive this, nut it's giving the weired output.


My file system is 

/dev/sg09/sv1         140471312 27446992 113024320    20%   /db/ffin1/data9
/dev/sg08/sv2         140462032 26272704 114189328    19%   /db/ffin1/data8
/dev/sg02/sv1         141274704 130280096 10994608    93%   /db/ffin1/data1
/dev/sg03/sv1         141307536 134482064  6825472    96%   /db/ffin1/data2
/dev/sg04/sv1         141300976 133642288  7658688    95%   /db/ffin1/data3
/dev/sg05/sv1         141291472 132425616  8865856    94%   /db/ffin1/data4
/dev/sg06/sv1         141346672 139491808  1854864    99%   /db/ffin1/data5
/dev/sg07/sv1         141315312 135477184  5838128    96%   /db/ffin1/data6
/dev/sg08/sv1         141235696 125286240 15949456    89%   /db/ffin1/data7

#!/sbin/sh
fsystem=$(bdf | grep data |grep ffin1 | awk '{print $6}')
for x in `bdf | grep data |grep ffin1 | awk '{print $5}'|grep -v u | cut -d "%" -f1 -`
do
echo "the $fsystem is $x"
done

after executing , it returns following:-

the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 89
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 96
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 99
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 94
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 95
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 95
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 92
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 19
the /db/ffin1/data7
/db/ffin1/data6
/db/ffin1/data5
/db/ffin1/data4
/db/ffin1/data3
/db/ffin1/data2
/db/ffin1/data1
/db/ffin1/data8
/db/ffin1/data9 is 20

Instead of cramming everything into backticks, you can do

command | while read TOKEN1 TOKEN2 TOKEN3 ...
do
        echo "First field is $TOKEN1"
        ...
done

no need to run STUFF=`awk | grep | sed | cut | foo | kitchen | sink`.

It would help to know what the output of 'bdf' looks like to tell why your program's doing what it is. (Unless that's the unlabelled output given earlier?) It's partly because 'for x in `junk`' splits on spaces, not just newlines. (the while read loop reads line-by-line.) It's also because fsystem stores every possible result in one variable, causing it to print every result every loop.

If I grasp your intent correctly now, how about:

bdf | grep "ffin1/data" | while read DEV A B C PERCENT FOLDER
do
        echo "$DEV = $FOLDER"
done