On Thu, Mar 25, 2010 at 03:32:25AM -0700, Rob Robason wrote: > The printf builtin is broken in many variations of use of '*' (e.g., "%.*s") > in a printf conversion spec to set field width and precision from argument > values.
The use of '*' as a field width is not required by POSIX. According to <http://www.opengroup.org/onlinepubs/9699919799/utilities/printf.html>: "No provision is made in this volume of POSIX.1-2008 which allows field widths and precisions to be specified as '*' since the '*' can be replaced directly in the format operand using shell variable substitution. Implementations can also provide this feature as an extension if they so choose." So, what you're asking for is a new feature; its absence is not a bug. > Compare to correct behavior of printf(1) (/usr/bin/printf) with same args > $ /usr/bin/printf "%.*s\n" 5 "Sample string" > Sampl On HP-UX 10.20: imadev:~$ /usr/bin/printf "%.*s\n" 5 "Sample string" printf: Error printing 5 printf: Error printing Sample string > printf(1): > "Interpreted sequences are: ... > "and all C format specifications ending with one of diouxXfeEgGcs, ... > "Variable widths are handled." That's the GNU implementation, which has apparently added the variable width feature. Bash hasn't added it (yet?).