${(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:
- If defined,
string2
is inserted once to the right of the word. - If the padded word is longer than
field_length_expr
, then it’s truncated to the field length.
If the padded word is shorter thanfield_length_expr
, thenstring1
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.
Links
Examples
- Right-padding of array elements into a string
- Output:
1 2
data=(a ab abc abcd) echo ${(r:5::-::_:)data}
1
a_--- ab_-- abc_- abcd_
BashSupport Pro is a Zsh IDE with support for ${(r)…} – try it now!