Your $cols interpolated variable looks like its number, for example, 10, so
"%${cols}s"
must interpolate and be equivalent
"%10s"
which is a valid format string.
If, however, $cols was anything other than a numeric or valid format, you will receive a warning.
For example, if:
$cols = "w";
which will cause "%ws" be used as a format string, indicating the error you specified:
Invalid conversion in printf: "%w"
Information on the current format can be found here .
martin clayton
source share