read a b= for c in ${a:?} {((d--))&&b+=$c\ ||{ d=${c/L} b+=${b:x=${c/R}*-3:-x} } } echo $b . *