#!/bin/bash head=$1 while [ ${#head} -gt 3 ]; do tail=${head: -3} head=${head:0: -3} if [ -z ${result} ]; then result=${tail} else result="${tail},${result}" fi if [ ${#head} -le 3 ]; then result="${head},${result}" fi done echo ${result}