Yesterday, a person on the Bug-bash asked: why [--help did not output help information. Someone answered him because coreutils provided the [command to accept the--HELP option, and Bash's own [command does not accept any options.] When you execute [--help ] in Bash, of course the first priority is the internal command [, not the external command [, the execution of /usr/bin/[--help(on my Mac is/bin/[) to get the help information he wants.
In fact, there are other external commands that have the same name as the internal commands provided by Bash, and the names of the commands found on my computer are listed below:
[
Alias
Bg
Cd
Command
Echo
False
Fc
Fg
Getopts
Hash
Jobs
Kill
Printf
Pwd
Read
Test
Time
True
Type
Ulimit
Umask
Unalias
Wait
Also, starting with Bash 4.4, most of the internal commands begin to accept the--HELP option, with two examples, such as the previous eval and source:
$ eval--help Bash:eval:--: Invalid option Eval:usage:eval [arg ...] $ source--help Bash:source:--: Invalid option Source:usage:source filename [arguments] |
And in Bash 4.4 It's like this:
$ eval--help Eval:eval [arg ...] Execute arguments as a shell command. Combine ARGs into a single string with the result as input to the shell, and execute the resulting commands. Exit Status: Returns exit status of command or success if command is null. $ source--help Source:source filename [arguments] Execute commands from a file in the current shell. Read and execute commands from the FILENAME of the current shell. The Entries in $PATH is used to find the directory containing FILENAME. If any ARGUMENTS is supplied, they become the positional parameters When FILENAME is executed. Exit Status: Returns the status of the last command executed in FILENAME; Fails if FILENAME cannot be read. |
I tried it in Bash 4.4 Alpha and still have a few commands that don't accept the--help option, and here's why I guess: first say Echo,echo--help can only output--help, the output of the other has compatibility issues. There are also some commands, such as true false: Maybe it's because these commands don't accept any options since ancient times, and test and [I don't know why.]
Another point of knowledge is that the person who raised the question also Huitie said, "I was through which [confirmed that the execution in Bash [is an external command]." Then someone corrects him, cannot use which to judge whether a command is an internal command or an external command, because which itself is an external command, it works by looking for an external command in PATH, it is impossible to know [in Bash is an internal command, you should use the Type command:
$ which [ /bin/[ $ type [ [is a shell builtin |
And the type command can also list internal and external commands in the order in which Bash is found:
$ TYPE-A [ [is a shell builtin [is/bin/[ |
Internal commands and external commands with the same name in Bash