在界定范围不同的外壳语言的问题? [英] Scoping problems in different shell languages?

查看:123
本文介绍了在界定范围不同的外壳语言的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看来,pdksh程序和mksh有作用域实现我的预期。

It appears that pdksh and mksh has the scoping implementation I expected.

例如:

readonly x='global'

f() {
  local x
  readonly x='f'
  echo $x
}

g() {
  local x
  readonly x='g'
  echo $x
}

echo $x

f 
g

echo $x

pdksh程序和mksh我产生预期的结果:

pdksh and mksh produce my expected result:

global
f
g
global

和击失败:

line 5: local: x: readonly variable

短跑和ksh93的失败我的期望了。 (我已经改变了本地排版 在ksh93的的测试。)

Dash and Ksh93 failed my expect, too. (I've changed local to typeset in Ksh93's test.)

这似乎令人困惑。

更新:我已经编辑了问题。这个问题之前没有以明确的方式表示。

UPDATE: I've edited the question. The question before is not stated in a clear way.

推荐答案

Bash和短跑,如果全局变量不是只读不会失败。

Bash and Dash don't fail if the global variable is not read only.

科恩(ksh93的)只有的的实例X 是只读不会失败。

Korn (ksh93) doesn't fail only if none of the instances of x are read only.

这篇关于在界定范围不同的外壳语言的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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