4

Similar to Why are parameters to Bash's builtin optional?, these commands print nothing and return exit code 0 if no parameters are provided. But unlike builtin, their help output state that at least one parameter is mandatory. Is this a bug, a feature, or did I misunderstand something?

$ bash --version
GNU bash, version 4.2.10(1)-release (x86_64-pc-linux-gnu)
$ type -a command
command is a shell builtin
$ type -a type
type is a shell builtin
$ help -s command
command: command [-pVv] command [arg ...]
$ help -s type
type: type [-afptP] name [name ...]
$ command
$ echo $?
0
$ type
$ echo $?
0

2 Answers 2

3

POSIX thinks the command parameter is required. So it could be a bug.

POSIX 2008 command specification

1
  • Looks like the type synopsis says the same - Optional parameters would be in brackets.
    – l0b0
    Apr 18, 2012 at 15:34
2

For command, the immediate explanation is probably that ksh does the same thing (at least ATT ksh93, pdksh and mksh do nothing when you run command with no argument, I don't have ATT ksh88 to test).

Why ksh behaves that way, I don't know. A tentative explanation is that command foo is a lot like foo, and if you leave out foo, you get a shell command that does nothing (but still performs redirections). Strangely, with ksh 93s+ 2008-01-31 (but not with pdksh, mksh, bash, ash or zsh), ksh -c 'foo=bar command; echo $foo' displays bar, which means that the assignment is treated as a shell variable assignment and not as a command-local environment assignment. This behavior is expected only of special built-in utilities, which command is not (the rationale explains why not). This looks like a bug in ksh93.

In ksh, builtin displays a list of built-in utilities, which is useful.

type is a different case: it accepts multiple arguments, and reports on each in turn (e.g. type ls cd). Having zero arguments is a natural continuation of this behavior.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .