Help us understand the problem. What are the problem?

posted at

updated at

Bash — echo --help でヘルプが表示されない理由から考える シェルの bultin コマンドなどなど


docker + ubuntu + bash

docker run --interactive --tty ubuntu /bin/bash


docker run --interactive ubuntu

( Docker— docker run -it の -t を抜くとどうなるか ( tty 指定なしの interactive モード ) - Qiita )

echo --help

ヘルプが表示されるのではなく、 --help という文字列が表示される。

$ echo --help



/bin/echo --help


$ /bin/echo --help

Usage: /bin/echo [SHORT-OPTION]... [STRING]...
  or:  /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.

  -n             do not output the trailing newline
  -e             enable interpretation of backslash escapes
  -E             disable interpretation of backslash escapes (default)
      --help     display this help and exit
      --version  output version information and exitEcho the STRING(s) to standard output.


NOTE: your shell may have its own version of echo, 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/>
Report echo translation bugs to <http://translationproject.org/team/>
Full documentation at: <http://www.gnu.org/software/coreutils/echo>
or available locally via: info '(coreutils) echo invocation'


GNU の echo コマンドは --help とか --version などのコマンドオプションをサポートしているらしい。

which してみる

/bin/echo が使われているような気がするが?

$ which echo


which は builtin コマンドを掴まえないみたいだ。


【 which 】コマンド――実行コマンドのフルパスを表示する:Linux基本コマンドTips(94) - @IT

type コマンドを打つ必要がある様子。

$ type echo

echo is a shell builtin

builtin って何よ?

シェルの組み込みコマンドで、実行形式の外部プログラム ( /bin/echo とか ) よりも速いらしい。

Shell builtins work significantly faster than external programs, because there is no program loading overhead. However, their code is inherently present in the shell, and thus modifying or updating them requires modifications to the shell.

Shell builtin - Wikipedia


enable コマンドで builin を無効化しても、ヘルプが表示されるようになる。

$ enable -n echo
$ echo --help

Usage: /bin/echo [SHORT-OPTION]... [STRING]...
  or:  /bin/echo LONG-OPTION
Echo the STRING(s) to standard output.


type コマンドの結果も変わっているのが分かる。

$ type echo

echo is hashed (/bin/echo)

enable って何よ?

shell の builin を有効化/無効化するコマンドらしい。

enable --help
enable: enable [-a] [-dnps] [-f filename] [name ...]
    Enable and disable shell builtins.

    Enables and disables builtin shell commands.  Disabling allows you to
    execute a disk command which has the same name as a shell builtin
    without using a full pathname.

      -a	print a list of builtins showing whether or not each is enabled
      -n	disable each NAME or display a list of disabled builtins
      -p	print the list of builtins in a reusable format
      -s	print only the names of Posix `special' builtins






Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Sign upLogin
Help us understand the problem. What are the problem?