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
- Next message: Chris F.A. Johnson: "Re: good practice invoking utilities from shell"
- Previous message: those who know me have no need of my name: "Re: differences in "read" builtin behaviour"
- In reply to: giacomo boffi: "Re: differences in "read" builtin behaviour"
- Next in thread: William Park: "Re: differences in "read" builtin behaviour"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
- Next message: Chris F.A. Johnson: "Re: good practice invoking utilities from shell"
- Previous message: those who know me have no need of my name: "Re: differences in "read" builtin behaviour"
- In reply to: giacomo boffi: "Re: differences in "read" builtin behaviour"
- Next in thread: William Park: "Re: differences in "read" builtin behaviour"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|
|