使用ksh93,如何安全地将二维索引数组初始化为(()) [英] With ksh93, how to safely init a 2-dimensioned indexed array to ( () )
本文介绍了使用ksh93,如何安全地将二维索引数组初始化为(())的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
使用ksh93,typeset -a arr=( () )
将创建arr[0]
作为空的复合变量而不是空的索引数组:
With ksh93, typeset -a arr=( () )
will create arr[0]
as an empty compound var rather than an empty indexed array:
$ typeset -a arr=( () )
$ typeset -p arr[0]
typeset -C arr[0]=()
$
那么在声明arr
var时如何将arr[0]
初始化为空的索引数组?
So how can I init arr[0]
to an empty indexed array when declaring the arr
var?
推荐答案
我发现了一种使用ksh的较新版本(尝试过93v- 2013-02-13
)的黑客方式:
I found a hacking way with newer versions (tried with 93v- 2013-02-13
) of ksh:
$ echo ${.sh.version}
Version AJMP 93v- 2013-02-13
$ typeset -p arr
$ typeset -a arr=( ( ${not_existing_array[@]:0:0} ) )
$ typeset -p arr
typeset -a arr=( () )
$ typeset -p arr[0]
typeset -a arr[0]
$
这是合理的,因为索引数组的空子集仍然是索引数组. :)
That's kind of reasonable as an empty subset of an indexed array is still an indexed array. :)
这篇关于使用ksh93,如何安全地将二维索引数组初始化为(())的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文