Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: create variable with calculated number of spaces.





On 2024-05-06 22:52, Roman Perepelitsa wrote:
You don't need to "cobble together complicated variables" here. Just
printf straight away to stdout.
I know, I  mean in other situations where the variable really is complicated.  I've seen 'printf  -v' offered previously to do some pretty fancy stuff. 

    % n=10
    % y=${(r:n:: :)}  # n spaces
    % x='hello'
    % z=${(r:n:: :)x}  # right-justified x
Jim Murphy offered:

        spacer=${(l:diff:::: :)}

... very much in the same school of thought.  Feels more 'direct', if that means anything.  Mark suggests I shouldn't worry so much about 'economy' -- I tend to not want to use an elephant's worth of functionality ( printf ) where a mouses worth will do.  But maybe that's not a valid way to think cuz I can't really anticipate how the shell will actually get the work done. 






Messages sorted by: Reverse Date, Date, Thread, Author