Minimum Index of all Characters in a String

In this blog, Sharing code to find Minimum Index value of all Characters present in a String. Consider a String “allabouttechnologies”.So, mininum Index for l is 1 not 2 and for a, its 0 not 3. str=”alllabouttechnologies”declare -A dict1 ##declare a dictionaryunset dict1 ##resetting dictionarynewstr=” ## creating Blank Stringn=${#str}i=0while [[ $i -lt $n ]]doChar=${str:$i:1}echo ${newstr}CharCntInNewStr=echo ${newstr} | grep ${Char} | wc -l ##If Character is not present, inserting into dictionary Index and Character itselfif [[ $CharCntInNewStr -eq “0” ]]thendict1[${i}]=${Char}echo ${dict1[${i}]}newstr=${newstr}${str:$i:1}fii=$(( $i + 1))donefor key in “${!dict1[@]}”; doecho “$key ${dict1[$key]}”done