Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

Required fields*

4
  • Thank you for the quick response. What I am understanding is this: printf "%55s and printf "%${width}" is the same thing correct? Using "%$width.${width}s tells printf to format the string with 50 chars padding and limit to 50 chars. Is that correct? Commented Mar 24, 2015 at 2:10
  • also what I am having a hard time with is the use of brackets with the variable. printf ""%$widths" generates an error but printf "%${width}" does not. But somehow printf "%$width.${width}s\n" works. Can you tell me why or direct me to something that explains this? I don't know the terminology to search for. Commented Mar 24, 2015 at 2:18
  • To respond to your first comment, "%${width}s" expands to "%55s". The format "%50.50s" would ask to pad to 50 characters and to print no more than 50 characters, so you are entirely correct on that part. To respond to your second comment, $width vs ${width} is a matter of bash variable expansion; I will amend my answer to talk about it. Commented Mar 24, 2015 at 2:55
  • I see it now and thank you for the terminology. It helps when you have an idea of what to ask Google to get the relevant results. Commented Mar 24, 2015 at 3:41