Shell Parameter Expansion

34日目

この記事を見て dev.classmethod.jp

この書き方を初めて見て調べてみました。

printf "processing ... %s\r" "${chars:$i:1}"

マニュアルを確認 tiswww.case.edu

${parameter:offset:length}
This is referred to as Substring Expansion. It expands to up to length characters of the value of parameter starting at the character specified by offset. If parameter is ‘@’, an indexed array subscripted by ‘@’ or ‘*’, or an associative array name, the results differ as described below. If length is omitted, it expands to the substring of the value of parameter starting at the character specified by offset and extending to the end of the value. length and offset are arithmetic expressions (see Shell Arithmetic).

こういうことね。

$ string=01234567890abcdefgh
$ echo ${string:7:2}
78