1
0
Fork 0
mirror of git://git.code.sf.net/p/zsh/code synced 2025-09-17 02:51:01 +02:00

37831: typeset: Document exit status difference from parameter assignment statements

This commit is contained in:
Daniel Shahaf 2016-01-29 09:18:34 +00:00
parent ca3bc0d95d
commit 3b69b121de
2 changed files with 22 additions and 0 deletions

View file

@ -1,3 +1,8 @@
2016-01-30 Daniel Shahaf <d.s@daniel.shahaf.name>
* 37831: Doc/Zsh/builtins.yo: typeset: Document exit status
difference from parameter assignment statements
2016-01-30 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp> 2016-01-30 Jun-ichi Takimoto <takimoto-j@kba.biglobe.ne.jp>
* 37838: Src/Builtins/rlimits.c, Src/Builtins/sched.c, * 37838: Src/Builtins/rlimits.c, Src/Builtins/sched.c,

View file

@ -1826,6 +1826,23 @@ reserved word interface for tt(typeset) may cause problems with the
output of `tt(typeset -p)', which assumes the reserved word interface is output of `tt(typeset -p)', which assumes the reserved word interface is
available in order to restore array and associative array values. available in order to restore array and associative array values.
Unlike parameter assignment statements, tt(typeset)'s exit status on an
assignment that involves a command substitution does not reflect the exit
status of the command substitution. Therefore, to test for an error in
a command substitution, separate the declaration of the parameter from its
initialization:
example(# WRONG
typeset var1=$(exit 1) || echo "Trouble with var1"
# RIGHT
typeset var1 && var1=$(exit 1) || echo "Trouble with var1"
)
To initialize a parameter var(param) to a command output and mark it readonly,
use tt(typeset -r )var(param) or tt(readonly )var(param) after the parameter
assignment statement.
If the shell option tt(TYPESET_SILENT) is not set, for each remaining If the shell option tt(TYPESET_SILENT) is not set, for each remaining
var(name) that refers to a parameter that is already set, the name and var(name) that refers to a parameter that is already set, the name and
value of the parameter are printed in the form of an assignment. value of the parameter are printed in the form of an assignment.