[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Bash true/false builtings undocumented? "false" not working?



On Fri, Aug 17, 2018 at 11:25:52AM +0200, tomas@tuxteam.de wrote:
> On Fri, Aug 17, 2018 at 06:46:54PM +1000, Zenaan Harkness wrote:
> > 1)
> > Bash man page largely fails to document the true and false builtins
> > AFAICT, except for this sentence just under the heading
> > "^SHELL BUILTIN COMMANDS":
> > 
> >  The :, true, false, and test builtins do not accept options and do
> >  not treat -- specially.
> > 
> > But whilst the subsequent list of Bash builtin commands DOES include
> > entries for ":" (the very first entry) and "test", it appears to fail
> > to include entries for "true" and for "false".
> > 
> > This would not matter so much except for the following:
> > 
> > 
> > 2)
> > Why is executing "false" prior to testing it's output, apparently
> > differen to executing "false" in a pipeline, e.g.:
> > 
> > $ false
> > $ test $? && echo ok || echo error $?
> > ok
> > $ false blah
> > $ test $? && echo ok || echo error $?
> > ok
> 
> Note that after false, 
> 
>   test $? && echo ok || echo error $?
> 
> expands (after variable expansion) to
> 
>   test 0 && echo ok || echo error 0
> 
> ... which ends up saying "ok", because test 0 succeeds :-)
> The only one-arg test which fails is test "".
> Yes, a bit unexpected, due to (a) the shell's evaluation model
> and (b) test's behaviour.
> 
> To defend bash's documenters (a bit) its help system provides you
> with tiny snippets of information (try "help false").

$ help false
false: false
    Return an unsuccessful result.

    Exit Status:
    Always fails.


That accords with my previous understanding, that the exist status of
running false gives something other than "success" (i.e. zero) - what
am I missing?


Reply to: