[sisyphus] баг в printf?

Eugeny Korekin =?iso-8859-1?q?az_=CE=C1_ftc=2Eru?=
Вт Мар 5 10:31:37 MSK 2002


"Dmitry V. Levin" <ldv на alt-linux.org> writes:

>> printf "%2$s %1$s" a b
>> printf: % : неверная директива


> Посмотрите на содержание "$s".

Мда, ошибся с кавычками, когда письмо писал.
$s тут ни при чем.

~$ printf '%2\$s %1\$s' a b
printf: %$:неверная директива
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
вот так на самом деле ругается.

Из орейливских Unix power tools:
------------------------------------------
Another utility called printf works like the printf(3) routine in the
C language; it handles escape sequences, lets you set field widths,
and more. (The GNU version is on the CD-ROM.) Here's an example. The
wc command gives the number of lines, words, and characters in a file,
followed by the filename. We pass those four fields in the wc output
to the printf command line with backquotes (9.16). (If you need a
reminder of wc's output, see article 29.6.) printf takes a formatting
command from its first argument. It outputs the fourth argument after
that (%4$s, the filename); the number of words from the second
argument, in a field five wide with leading zeroes (%2$05s); and the
number of lines from the first argument (%1$s); with a newline (\n) to
finish the line:
$ printf 'The %4$s file has %2$05s words on %1$s lines.\n' `wc count`
The count file has 00235 words on 42 lines.
--------------------------------------------



-- 
	Best regards, -- Eugeny.

As of next Thursday, UNIX will be flushed in favor of TOPS-10.
Please update your programs.




Подробная информация о списке рассылки Sisyphus