申报,排版和局部变量在Bash中之间的差异 [英] Differences between declare, typeset and local variable in Bash

查看:155
本文介绍了申报,排版和局部变量在Bash中之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Bash中输入变量,就是之间的差别声明排版?当一个函数内部使用的:是什么之间的差别声明排版本地

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?

我所遇到的唯一的区别是,排版移植到的ksh脚本。除此之外,还有为什么要成为pferred比其他$ P $的原因是什么?

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?

更新:新增本地来的问题。

推荐答案


  • 差异排版声明

  • Difference between typeset and declare:
  • 前者更便于携带(例如KSH),而后者更preferable时,便携性不是一个问题。

    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:

    前者指的是后者,但功能更强大。例如,声明-ix 使 X 整数属性,声明-rx ,使 X 只读等。

    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.

    这篇关于申报,排版和局部变量在Bash中之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆