ksh : Building an array based on condition result

I want to build an Errorlog. I would like to build an array as I move through the if statements and print the array once all error conditions have been defined. The results need to be comma delimited.

tsver will be static "1.9.6(2)"
other vars $prit $lt $rt can have the same or a different value as tsver.
For those vars not matching tsver, their values should be written to a csv.

Example errorlog file

This code works, but it seems cheep .... My question is how do I build an array in ksh as I step through the version mismatch tests ?

 if [[ "$prit" != "$tsver" ]]
   then 
   echo -n "$prit," >> Errorlog
   else 
   echo -n "," >> Errorlog
  fi
#
if [[ "$lt" != "$tsver" ]]
   then
   echo -n "$lt," >> Errorlog
   else
   echo -n "," >> Errorlog
  fi

#
if [[ "$rt" != "$tsver" ]]
   then
   echo -n "$rt," >> Errorlog
   else
   echo -n "," >> Errorlog
  fi

Looking through Unix shell by Quigley and searching the web. But havent found anything that gives a good example.

THANKS !!

This doesn't seem to need any array. Here is what I would do... (untested)

output=""
[[ "$prit" != "$tsver" ]] && output="${output}${prit}"
output="${output},"
[[ "$lt" != "$tsver" ]] && output="${output}${lt}"
output="${output},"
[[ "$rt" != "$tsver" ]] && output="${output}${rt}"
output="${output},"
echo $output >> Errorlog

Whatever you do you need one last echo with no -n so you terminate your line.

1 Like