Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

3
  • concise and elegant solution. Commented May 30, 2019 at 21:32
  • 3
    You can get rid of the $((...)); the off and len part of the ${var:off:len} substitution are already evaluated as arithmetic expressions. Example: foo=01234567; echo "${foo:0:${#foo}/2} ${foo:${#foo}/2}". That's documented, and it's the same in zsh and ksh93 as in bash. Commented May 30, 2019 at 21:47
  • 3
    Note: If the length of the string is odd, this will still split it into two parts, but the second will be a character longer. Commented May 31, 2019 at 7:39