In Perl you have this:
% perl -e 'print "a" x 5, "\n"'
aaaaa
With that you can easily create a separator string consisting out of 60 spaces.
I always missed this in my shell - until now.
In Zsh have the following expansion:
l:expr::string1::string2:
Pad the resulting words on the left. Each word will be truncated if required and placed in a field expr characters wide.
See zsh.dotsrc.org.
There is also a r: variant which operates in the same way.
And lo and behold:
% echo ${(r:40::-:)A}
----------------------------------------
No more:
A="------------------------------------"
2 comments
Well Miek,
In zsh it's a nice, single command function.
In bash it takes two steps, something like
This is all shell internal, so performance should be good.
Like the zsh trick better, though.
In zsh it's a nice, single command function.
In bash it takes two steps, something like
A="$(printf "%-20s", "")"
A="${A// /-}"
This is all shell internal, so performance should be good.
Like the zsh trick better, though.
Still a lot nicer than:
I like it.
LINE="--------------------------"I like it.
