任何人都可以用现实中的例子解释声明和排版之间的区别。
任何人都可以用现实中的例子解释声明和排版之间的区别。
Answers:
在bash
,typeset
并且declare
是完全一样的。唯一的区别是typeset
被认为已过时。
typeset: typeset [-aAfFgilrtux] [-p] name[=value] ...
Set variable values and attributes.
Obsolete. See `help declare'.
手册页甚至还列出了它们:
declare [-aAfFgilrtux] [-p] [name[=value] ...]
typeset [-aAfFgilrtux] [-p] [name[=value] ...]
Declare variables and/or give them attributes.
typeset
可移植到其他一些外壳,例如ksh93
。如果您希望跨外壳可移植性,请使用typeset
(并确保您称呼它的方式可移植)。如果您不关心这种可移植性,请使用declare
。
help typeset
,而不是中man typeset
。
typeset
被认为已经过时了?
我知道在什么情况下declare
可以避免邪恶eval
:变量间接:
$ var=foo
$ x=var
$ declare "$x=another_value"
$ echo $var
another_value
typeset
和的问题declare
?