${(l:field_length_expr::string1::string2:)…}: Left padding of words
l controls left-padding of the resulting words.
The padding of a word follows the following steps:
- If defined,
string2is inserted once to the left 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, thenstring1is 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 left. If it’s empty, then
$IFSis used. string2- This string is inserted once to the left of a word before
string1is used as padding of the remaining space. If it’s empty, then$IFSis used.
Links
Examples
- Left-padding of array elements into a string
- Output:
1 2data=(a ab abc abcd) echo ${(l:5::-::_:)data}1---_a --_ab -_abc _abcd
BashSupport Pro is a Zsh IDE with support for ${(l)…} – try it now!