> Date: Fri, 12 Mar 2010 17:29:44 +0100
> From: [email protected]
> To: [email protected]
> Subject: [ast-users] How to retrieve result code of command substitution in
> assignment?
>
> Hello,
>
> how could I (in a reliable, portable way) retrieve the exit code of
> the program "urldecode" in the following code fragment:
>
> var=$(echo "$url" | urldecode)
>
> Tests show that the result of the assignment is the result of the
> pipeline started for command substition (here: the exit code of
> "urldecode"). But is this something to depend upon, or is it
> an implementation detail?
I cannot find it explicitly defined in the POSIX standard. But...
If you consider the subshell expansion $(...) as a semantic
extension of a subshell command (...) then POSIX says:
Pipelines
Exit Status
If the reserved word ! does not precede the pipeline, the exit status
shall be the exit status of the last command specified in the pipeline.
Grouping Commands
(compound-list)
Execute compound-list in a subshell environment; see Shell
Execution Environment. Variable assignments and built-in commands
that affect the environment shall not remain in effect after the
list finishes.
Exit Status
The exit status of a grouping command shall be the exit status of
compound-list.
Extending the results to $(...) would match the observed behaviour.
Janis
>
> Alternatively the result of "var=$(cmdsubst)" could be the result
> of the assignment, e.g. an error if the command substitution fails
> (e.g. "out of processes").
>
> Maybe the exit code is a combination: "0" if everything works
> without error, different from zero if *anything* goes wrong, either
> in the command substitution, during the assignment?
>
> Heiner
>
> --
> ___ _
> / __| |_ _____ _____ _ _ Heiner STEVEN <[email protected]>
> \__ \ _/ -_) V / -_) ' \ Shell Script Programmers: visit
> |___/\__\___|\_/\___|_||_| http://www.shelldorado.com/
> _______________________________________________
> ast-users mailing list
> [email protected]
> https://mailman.research.att.com/mailman/listinfo/ast-users
_________________________________________________________________
http://redirect.gimas.net/?n=M1003xIMVideochat2
Treffe Freunde im Messenger Videochat!_______________________________________________
ast-users mailing list
[email protected]
https://mailman.research.att.com/mailman/listinfo/ast-users