Não é possível usar --help com printf

0

A maioria dos programas imprime o uso e sai com "--help". Mas não consigo trabalhar com printf :

$ printf --help
bash: printf: --: invalid option
printf: usage: printf [-v var] format [arguments]

man 1 printf diz:

SYNOPSIS

       printf FORMAT [ARGUMENT]...

       printf OPTION

DESCRIPTION

       Print ARGUMENT(s) according to FORMAT, or execute according to OPTION:

       --help display this help and exit

Também não há nada de errado com o código fonte do 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 que não consigo fazer printf --help ?

    
por user543212 13.05.2016 / 08:35

3 respostas

2

Existem dois tipos de printf . O fornecido por coreutils e aquele fornecido pelo Bash como um shell embutido.

$ 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 obter ajuda sobre o built-in do Bash, use o comando help :

$ help printf
printf: printf [-v var] format [arguments]
    Formats and prints ARGUMENTS under control of the FORMAT.
...
    
por user543212 13.05.2016 / 08:40
1

Existem dois printfs disponíveis para você: o shell embutido e um executável. O shell embutido é descrito em man bash . Não suporta --help . Você pode, no entanto, obter informações sobre isso com help printf .

man 1 printf descreve /usr/bin/printf e suporta, de fato, --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 
$ /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 %pre% or %pre%NNN

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'
or %pre%NNN 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'
    
por John1024 13.05.2016 / 08:40
1

printf é um shell ( bash ) embutido também. Então quando você corre

printf --help

o printf embutido é executado porque, por padrão, os internos sempre têm precedência sobre os externos e não possui a opção --help , daí o erro.

Para encontrar todos os executáveis printf disponíveis:

type -a printf

Ele mostrará os executáveis na ordem de precedência.

Você pode verificar a página help do printf integrado por:

help printf

Por outro lado, se você quiser executar o printf externo, siga um destes procedimentos:

command printf
"printf"
'printf'
\printf
    
por heemayl 13.05.2016 / 08:42