Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.debian.user > #199276

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

From Stefan Krusche <linux@stefan-krusche.de>
Newsgroups linux.debian.user
Subject Re: Bash true/false builtings undocumented? "false" not working?
Date 2018-08-23 15:00 +0200
Message-ID <wpXnr-4bF-1@gated-at.bofh.it> (permalink)
References <wnICd-6jg-3@gated-at.bofh.it> <wnJeV-6KG-5@gated-at.bofh.it> <wnJoB-6ND-1@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


Am Freitag 17 August 2018 schrieb Zenaan Harkness:
> 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?

Nothing. What Tomás wrote is false (has exit code "1" ;-)

This:

  test $? && echo ok || echo error $?

does *not* expand as Tomás said to:

  test 0 && echo ok || echo error 0

but to:

  test 1 && echo ok || echo error 1

And "test 1" also succeeds, see Greg's message.

Kind regards,
Stefan

Back to linux.debian.user | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-17 10:50 +0200
  Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-17 11:00 +0200
  Re: Bash true/false builtings undocumented? "false" not working? Nicolas George <george@nsup.org> - 2018-08-17 11:00 +0200
    Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-17 11:30 +0200
    Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-17 11:40 +0200
      Re: Bash true/false builtings undocumented? "false" not working? Nicolas George <george@nsup.org> - 2018-08-17 11:40 +0200
      Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 12:20 +0200
      Re: Re: Bash true/false builtings undocumented? "false" not working? Clive Standbridge <list-user@tgstandbridges.plus.com> - 2018-08-17 14:10 +0200
        Re: Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 15:40 +0200
      Re: Bash true/false builtings undocumented? "false" not working? Greg Wooledge <wooledg@eeg.ccf.org> - 2018-08-17 14:30 +0200
        Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 15:50 +0200
          Re: Bash true/false builtings undocumented? "false" not working? Greg Wooledge <wooledg@eeg.ccf.org> - 2018-08-17 16:20 +0200
            Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 16:40 +0200
              Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-18 01:10 +0200
        Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-18 01:30 +0200
  Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 11:30 +0200
    Re: Bash true/false builtings undocumented? "false" not working? Zenaan Harkness <zenaan@freedbms.net> - 2018-08-17 11:40 +0200
      Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-17 11:50 +0200
        Re: Bash true/false builtings undocumented? "false" not working? tomas@tuxteam.de - 2018-08-17 12:00 +0200
      Re: Bash true/false builtings undocumented? "false" not working? Stefan Krusche <linux@stefan-krusche.de> - 2018-08-23 15:00 +0200
        Re: Bash true/false builtings undocumented? "false" not working? <tomas@tuxteam.de> - 2018-08-23 16:30 +0200

csiph-web