Need help with shell script

Hi,

I have a shell script which reads a file and checks for the attributes and its values in the file.The values are comma/semicolon separated so a splitting mechanism is used.Here is the relevant part of the script -

--------------------------------------------------------------

 # Get a count of how many elements are in each row and keep track of the max
  i=1
  while [ -n "${!i}" ]; do
    local val="${!i}"
    eval "$val=\"${!val};\""
    eval "let __tally_$val=0"
    #SK001 Start
    #Added one more validation in while statement for length validation
    #while [ "${!val}" != "" ]; do
    while [ "${!val}" != "" ] && [ "${!val}" != ";" ]; do
    #SK001 End
      eval "$val=\"${!val#*[,;]}\""
      eval "let __tally_$val++"
    done
    local count
    eval "count=\$__tally_$val"
echo "<$count>"
    if [ "$count" -gt "$max" ]; then
      max=$count
    fi
    let i++
  done

----------------------------------------------------------------
I have made bold the line which does the splitting part.An example of an attribute value is - CFG_DISKLETTERS = "a,b;c,d"
If it is the above,the number of diskletters is populated as 4. But if the attribute value is something like this - CFG_DISKLETTERs = "a,b;c,,,d"
then even the commas are counted and number of values is populated as 6.
I am not able to understand the splitting mechanism being used so I am not able to correct the problem.Please help.

Hi,

Please at least let me know how the following line works to split a string -

eval "$val=\"${!val#*[,;]}\""

IGITT!

Sorry, but these lots of "eval" are giving me the creeps. ;-))

If you don't mind: please post some sample file content and describe what you want to do with it/give us an example how the result should look like.

I don't know exactly what your script is supposed to do but i am 110% sure there will be a much simpler way of doing. I'll be gladly helping you, but i think you have gotten yourself into a dead end of scripting and instead of trying to correct some minor problem it will be better to write the whole script anew.

(I hope you don't take my initial reaction personal - just trying to be funny.)

bakunin

Hi,
This is the content of the file -

---------------------------------------------------------------------------
CFG_VERSION=320
CFG_EMCMODEL="118032400-A06"
CFG_CHASSIS="1"
CFG_DISKS="/dev/cstarda,/dev/cstardb;/dev/cstardc,/dev/cstardd"
CFG_BLOBS="/dev/cstarda10,/dev/cstardb10;/dev/cstardc10,/dev/cstardd10"
CFG_BLOBSIZES="314600894,314600894;314600894,314600894"
CFG_MOUNTS="/mnt/1,/mnt/2;/mnt/3,/mnt/4"
CFG_DISKLETTERS="a,b;c,,,d"
CFG_DISKSIZES="316336104,316336104;316336104,316336104"
CFG_DISKLBAS="0-632672207,0-632672207;0-632672207,0-632672207"
CFG_BLOBLBAS="3470041-632671829,3470041-632671829;3470041-632671829,3470041-632671829"
CFG_DISKSERIALS="A82JZ4AE,A80ZETCE;A80Z7KQE,A80ZFG6E"
CFG_SWAP="/dev/cstarda9,/dev/cstardb9,/dev/cstardc9,/dev/cstardd9"
CFG_SERVICE_PARTS=""
CFG_SERVICE_MOUNTS=""
CFG_BLOBSIZE=307227
CFG_DISKLAYOUT="0"
CFG_SAFECAPACITY="sfc_empty_threshold=5242880,blc_reserve_size=35433480192,bi_engineering_buffer=104857600,bi_reserve_size=56908316672"
CFG_RAID_PARTS="/dev/cstarda3,/dev/cstarda5,/dev/cstarda6,/dev/cstarda7,/dev/cstarda8,/dev/cstardb3,/dev/cstardb5,/dev/cstardb6,/dev/cstardb7,/dev/cstardb8,/dev/cstardc3,/dev/cstardc5,/dev/cstardc6,/dev/cstardc7,/dev/cstardc8,/dev/cstardd3,/dev/cstardd5,/dev/cstardd6,/dev/cstardd7,/dev/cstardd8"
CFG_RAID_MOUNTS="/,/usr,/usr/java,/home,/var"
CFG_RAIDLBAS="64260-273104,273106-883574,883576-1092419,1092421-1301264,1301266-3357584,64260-273104,273106-883574,883576-1092419,1092421-1301264,1301266-3357584,64260-273104,273106-883574,883576-1092419,1092421-1301264,1301266-3357584,64260-273104,273106-883574,883576-1092419,1092421-1301264,1301266-3357584"
CFG_NICS="eth0;00:e0:81:60:be:ae,eth1;00:e0:81:60:be:ad,eth2;00:0e:0c:22:96:62"
CFG_EXTERNAL_NET="no"
CFG_DUMPDIR="/mnt/1/service/java_dumps"
CFG_VOLUMES="1,2;3,4"
CFG_VOLUME_UUIDS="e08160beae56e81f39d408,e08160beae56e81f58f258;e08160beae56e820138307,e08160beae56e821311720"
CFG_DISKIDS="4034647370894973003,4034647370799967203;4034647370799629451,4034647370799996795"
FILECHECKSUM=e6ce79b201cf604b62ee09d2ad850604
-----------------------------------------------------------------------------

This is part of the output (i have deliberately put "echo" statements) which is going wrong.
<CFG_DISKLETTERS> <c,,,d;>
<CFG_DISKLETTERS> <,,d;>
<CFG_DISKLETTERS> <,d;>
<CFG_DISKLETTERS> <d;>
<CFG_DISKLETTERS> <>
<CFG_DISKLETTERS> <>
<6>

As you can see in the file,I have put extra commas in a value CFG_DISKLETTERS and thus,instead of 4 it is giving 6 values.I hope it explains you the sitaution a bit better.Thankx for any help.