Re: differences in "read" builtin behaviour

From: those who know me have no need of my name (not-a-real-address_at_usa.net)
Date: 02/28/04


Date: 28 Feb 2004 22:46:19 GMT

in comp.unix.shell i read:

>i have just read the thread
> "Bash shell is always returning last exit status of the pipe"
>and i _think_ that i got it, but if someone were so kind, etc

read the documentation instead, in particular for the issue mentioned in
the subject and to which you attached this article is described in the last
sentence of the `pipelines' description in the shell grammar section.

as to exit status, again you should read the documentation; a summary of
which is that every command that is run returns a numeric value when it
terminates, and that value is stored in the ? special variable and the
PIPESTATUS array (the last element of which is the same as $?), e.g.,

  $ true ; echo $?
  0
  $ false ; echo $?
  1
  $ true | false ; echo $?
  1
  $ false | true ; echo $?
  0
  $ false | true ; echo ${PIPESTATUS[@]}
  1 0

every command returns an exit status, even those built-in to bash, e.g.,
echo always succeeds:

  $ false ; echo $? ; echo $?
  1
  0

running a command in the background always succeeds:

  $ false & echo $?
  [1] 2178
  0
  $ no-such-command & echo $?
  [1] 2180
  0
  $ bash: no-such-command: command not found

  [1]+ Exit 127 no-such-command

the exit status of a compound command is the exit status of the last
command in the list, e.g.,

  $ { false; echo $?; false; }; echo $?
  1
  1

exit status can be used immediately by some shell commands, e.g.,

  $ if true ; then echo true; else echo false; fi
  true
  $ if false; then echo true; else echo false; fi
  false
  $ if true | false; then echo true; else echo false; fi
  false
  $ if false | true; then echo true; else echo false; fi
  true

-- 
a signature


Relevant Pages

  • Re: Shell Script to Remove Old Files
    ... Note it needs a TSM server: ... # Verify command line arguments ... echo "\nError: $STARTDIR does not exist.\n" ...
    (comp.unix.admin)
  • Re: Persisting env vars in cmd windows
    ... more about batch files as you go on, ... echo The time is %time::=.% ... But the piece de resistance was the "start" command, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... But the piece de resistance was the "start" command, ... - Have all code for the one project in one single batch file. ... @echo off ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)
  • Re: Persisting env vars in cmd windows
    ... even though it applies to any command, e.g. echo, copy, ... Similarly the syntax for the extremely powerful "for" command ... more about batch files as you go on, ... echo:: ERROR ERROR ERROR ERROR ...
    (microsoft.public.win2000.general)