${(r:field_length_expr::string1::string2:)…}: Right padding of words

r controls right-padding of the resulting words.

The padding of a word follows the following steps:

  1. If defined, string2 is inserted once to the right of the word.
  2. If the padded word is longer than field_length_expr, then it’s truncated to the field length.
    If the padded word is shorter than field_length_expr, then string1 is inserted as many times as necessary to reach the field length.

Options

field_length_expr
Length of the field to display each word. Longer words are truncated to fit into the field.
string1
Words shorter than a field are padded with this string on the right. If it’s empty, then $IFS is used.
string2
This string is inserted once to the right of a word before string1 is used as padding of the remaining space. If it’s empty, then $IFS is used.

Examples

Right-padding of array elements into a string
1
2
data=(a ab abc abcd)
echo ${(r:5::-::_:)data}
Output:
1
a_--- ab_-- abc_- abcd_
BashSupport Pro is a Zsh IDE with support for ${(r)…}try it now!
© 2020–2024 Joachim Ansorg
Imprint
Privacy Policy
Legal