Это переносимо:
a="$(command)" # Get the output of the command.
b="????" # as many ? as characters are needed.
echo ${a%"${a#${b}}"} # select that many chars from $a
Создание строки переменной длины из символов имеет отдельный вопрос здесь .