Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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
share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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

POSIX 2008 command specification

share|improve this answer
    
Looks like the type synopsis says the same - Optional parameters would be in brackets. –  l0b0 Apr 18 '12 at 15:34
add comment

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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.