I am working with GRASS and I have a problem with a one-dimensional vector of numbers. Now, I want to print the length of that vector because my output is looks like this:(1,2,3,4,5,6,7,8,9,)when it should look like this:(1,2,3,4,5,6,7,8,9)i.e., I don't need the last separator. Is there a way to do that?I want POSIX-compliant solutions; no bashisms.My code looks like this:for i in $CATSdo  step=$step$i, echo $step g.region --overwrite vector=region_uspo_$i, save=regions_uspo regions_uspos=region_$i, echo $regions_usposdone
String length with shell script
shell script
Remove the last comma after you've finished building the string.for donestep=${step%,}regions_uspos=${regions_uspos%,}${VARIABLE%PATTERM} expands to the value of VARIABLE with the shortest suffix matching PATTERN} removed. This construct is supported in every POSIX shell. It's supported in all BusyBox configurations as well.If you need the intermediate strings without a trailing comma, you can strip off the trailing comma inside the loop. Alternatively, build the strings without a trailing comma by adding a comma before the appended element. To avoid having an initial comma, detect the first iteration through the loop.first=1for  do  if [ -n $first ]; then    first=  else    step=$step,    regions_uspos=$regions_uspos,  fi  step=$step$i  done