La mayoría de los programas imprimen el uso y salen con "--help". Pero no puedo hacer que funcione con printf
:
$ printf --help
bash: printf: --: invalid option
printf: usage: printf [-v var] format [arguments]
man 1 printf
dice:
SINOPSIS
imprimirfFORMATO [ARGUMENTO]...
imprimirfOPCIÓN
DESCRIPCIÓN
Imprima ARGUMENTO(s) según FORMATO, o ejecute según OPCIÓN:
--ayudamostrar esta ayuda y salir
Tampoco hay nada malo en elcódigo fuente de coreutils:
/* We directly parse options, rather than use parse_long_options, in
order to avoid accepting abbreviations. */
if (argc == 2)
{
if (STREQ (argv[1], "--help"))
usage (EXIT_SUCCESS);
if (STREQ (argv[1], "--version"))
{
version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS,
(char *) NULL);
return EXIT_SUCCESS;
}
}
¿Por qué no puedo hacerlo printf --help
?
Respuesta1
Hay dos tipos de printf
. El proporcionado por coreutils y el proporcionado por Bash como shell integrado.
$ type printf
printf is a shell builtin
$ /usr/bin/printf --help
Usage: /usr/bin/printf FORMAT [ARGUMENT]...
or: /usr/bin/printf OPTION
Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:
...
Para obtener ayuda sobre la función integrada de Bash, utilice el help
comando en su lugar:
$ help printf
printf: printf [-v var] format [arguments]
Formats and prints ARGUMENTS under control of the FORMAT.
...
Respuesta2
Hay dos printfs disponibles: el shell integrado y un ejecutable. El shell incorporado se describe en man bash
. No es compatible --help
. Sin embargo, puedes obtener información al respecto con help printf
.
man 1 printf
describe /usr/bin/printf
y, de hecho, admite --help
:
$ /usr/bin/printf --help
Usage: /usr/bin/printf FORMAT [ARGUMENT]...
or: /usr/bin/printf OPTION
Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:
--help display this help and exit
--version output version information and exit
FORMAT controls the output as in C printf. Interpreted sequences are:
\" double quote
\\ backslash
\a alert (BEL)
\b backspace
\c produce no further output
\e escape
\f form feed
\n new line
\r carriage return
\t horizontal tab
\v vertical tab
\NNN byte with octal value NNN (1 to 3 digits)
\xHH byte with hexadecimal value HH (1 to 2 digits)
\uHHHH Unicode (ISO/IEC 10646) character with hex value HHHH (4 digits)
\UHHHHHHHH Unicode character with hex value HHHHHHHH (8 digits)
%% a single %
%b ARGUMENT as a string with '\' escapes interpreted,
except that octal escapes are of the form \0 or \0NNN
and all C format specifications ending with one of diouxXfeEgGcs, with
ARGUMENTs converted to proper type first. Variable widths are handled.
NOTE: your shell may have its own version of printf, which usually supersedes
the version described here. Please refer to your shell's documentation
for details about the options it supports.
GNU coreutils online help: <http://www.gnu.org/software/coreutils/>
Full documentation at: <http://www.gnu.org/software/coreutils/printf>
or available locally via: info '(coreutils) printf invocation'
Respuesta3
printf
También hay un shell ( bash
) incorporado. Entonces cuando corres
printf --help
el integrado printf
se ejecuta porque de forma predeterminada los integrados siempre tienen prioridad sobre los externos y no tiene --help
opción, de ahí el error.
Para encontrar todos los printf
ejecutables disponibles:
type -a printf
Mostrará los ejecutables en orden de precedencia.
Puede consultar la help
página integrada printf
mediante:
help printf
Por otro lado, si desea ejecutar el archivo externo printf
, realice cualquiera de las siguientes acciones:
command printf
"printf"
'printf'
\printf