Die meisten Programme drucken die Verwendung und beenden sich mit „--help“. Aber ich bekomme es nicht zum Laufen mit printf
:
$ printf --help
bash: printf: --: invalid option
printf: usage: printf [-v var] format [arguments]
man 1 printf
sagt:
ZUSAMMENFASSUNG
druckenfFORMAT [ARGUMENT]…
druckenfMÖGLICHKEIT
BESCHREIBUNG
ARGUMENT(E) entsprechend FORMAT drucken, oder entsprechend OPTION ausführen:
--helfendiese Hilfe anzeigen und beenden
Es ist auch nichts falsch an derCoreutils-Quellcode:
/* 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;
}
}
Warum kann ich das nicht tun printf --help
?
Antwort1
Es gibt zwei Typen von printf
. Den einen, der von Coreutils bereitgestellt wird, und den anderen, der von Bash als integrierte Shell bereitgestellt wird.
$ 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:
...
Um Hilfe zu den integrierten Funktionen von Bash zu erhalten, verwenden Sie help
stattdessen den folgenden Befehl:
$ help printf
printf: printf [-v var] format [arguments]
Formats and prints ARGUMENTS under control of the FORMAT.
...
Antwort2
Ihnen stehen zwei printfs zur Verfügung: das Shell-Builtin und eine ausführbare Datei. Das Shell-Builtin wird in beschrieben man bash
. Es unterstützt nicht --help
. Sie können jedoch mit Informationen darüber erhalten help printf
.
man 1 printf
beschreibt /usr/bin/printf
und unterstützt tatsächlich --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'
Antwort3
printf
ist auch eine Shell ( bash
) eingebaut. Wenn Sie also
printf --help
die integrierten printf
werden ausgeführt, da die integrierten standardmäßig immer Vorrang vor den externen haben und keine --help
Option besteht, daher der Fehler.
So finden Sie alle verfügbaren printf
ausführbaren Dateien:
type -a printf
Es werden die ausführbaren Dateien in der Reihenfolge ihrer Priorität angezeigt.
help
Sie können die Seite mit den integrierten Funktionen wie folgt überprüfen printf
:
help printf
Wenn Sie hingegen die externe Version ausführen möchten printf
, führen Sie einen der folgenden Schritte aus:
command printf
"printf"
'printf'
\printf