Differences between declare, typeset and local variable in Bash

后端 未结 3 1503
终归单人心
终归单人心 2021-01-31 14:22

When typing variables in Bash, what is the difference between declare and typeset? When used inside a function: what is the difference between de

3条回答
  •  鱼传尺愫
    2021-01-31 14:44

    • Difference between typeset and declare:

    The former is more portable(e.g. ksh), while the latter is more preferable when portability is not a concern.

    • Difference between 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.

提交回复
热议问题