Why are parameters to Bash's builtin optional?

2012-04-18 Thread Victor Engmark
(Re-posted from Stack Overflow 
)

Running simply `builtin` prints nothing and returns exit code 0. This is in 
accordance with `help builtin`, which shows all parameters as optional. But why 
isn't this no-op an error? Is there a use case for this? A more useful result 
would be an error code or, even better, listing the currently available 
builtins.

Cheers,
V


Shouldn't "type" and "command" complain if there are no parameters?

2012-04-18 Thread Victor Engmark
Re-post from 
:

[T]hese commands print nothing and return exit code 0 if no parameters are 
provided. But [...] `help command` and `help type` both 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 ...]
victor@victor:/home/victor/taclom/rails (master *$)
$ help -s type
type: type [-afptP] name [name ...]
$ command
$ echo $?
0
$ type
$ echo $?
0


Re: Why are parameters to Bash's builtin optional?

2012-04-18 Thread Chet Ramey
On 4/18/12 9:18 AM, Victor Engmark wrote:
> (Re-posted from Stack Overflow 
> )
> 
> Running simply `builtin` prints nothing and returns exit code 0. This is in 
> accordance with `help builtin`, which shows all parameters as optional. But 
> why isn't this no-op an error? Is there a use case for this? A more useful 
> result would be an error code or, even better, listing the currently 
> available builtins.

What's the use case for having it be an error?  I can see printing a list
of builtins, though `enable' already does that.

-- 
``The lyf so short, the craft so long to lerne.'' - Chaucer
 ``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, ITS, CWRUc...@case.eduhttp://cnswww.cns.cwru.edu/~chet/



Re: Why are parameters to Bash's builtin optional?

2012-04-18 Thread Victor Engmark
On Wednesday, April 18, 2012 4:36:36 PM UTC+2, Chet Ramey wrote:
> On 4/18/12 9:18 AM, Victor Engmark wrote:
> > (Re-posted from Stack Overflow 
> > )
> > 
> > Running simply `builtin` prints nothing and returns exit code 0. This is in 
> > accordance with `help builtin`, which shows all parameters as optional. But 
> > why isn't this no-op an error? Is there a use case for this? A more useful 
> > result would be an error code or, even better, listing the currently 
> > available builtins.
> 
> What's the use case for having it be an error?

Since it's a nonsensical command, and since developers who haven't learned 
proper quoting shouldn't be shot too hard in the foot when they run `builtin 
$empty`. Or maybe they should be - Quoting is such a different matter from 
mainstream languages (and *much* more complex) that maybe `builtin` should 
print simply "Use More Quotes!" Seriously though, Bash is difficult enough as 
it is, and a spoonful of language fussiness is worth a ton of guard code.

>  I can see printing a list of builtins, though `enable' already does that.

I guess the difference would be that `builtin` prints *all* builtins, and 
*never* modifies their state.

Cheers,
V