When typing variables in Bash, what is the difference between declare
and typeset
? When used inside a function: what is the difference between declare
and typeset
and local
?
The only difference I have come across is that typeset is portable to ksh scripts. Other than that, are there any reasons why one should be preferred over the other?
UPDATE: Added local
to the question.
typeset
and declare
:The former is more portable(e.g. ksh), while the latter is more preferable when portability is not a concern.
declare
(or typeset
) and local
when used inside a function:The former implies the latter, but more powerful. For example, declare -i x
makes x
have the integer
attribute, declare -r x
makes x
readonly, etc.