【问题标题】:Equivalent typeset -n options for HP/SOLHP/SOL 的等效排版 -n 选项
【发布时间】:2012-09-24 19:32:11
【问题描述】:

这是一个大得多的脚本的简化部分。我使用 i 作为循环遍历一组字符串。

我有多个字符串 "word1 word2 word3 word4 .....wordx" 我正在循环遍历

i=1
typeset "STRING$i=`echo $string | cut -d' ' -f1-50`"
typeset -n NEWVAR="STRING$i"
do_stuff_here_w_NEWVAR
done

这在 Linux 上效果很好,但我的 HP 和 SOL 机器不喜欢 typeset-n...我可以在这里做什么来代替 HP 或 Solaris 的 -n? 当我在我的盒子上运行 nameref 时,我得到 nameref:not found

【问题讨论】:

  • 对于solaris,看看能不能找到ksh93或者dtksh。 ksh88 不支持 Namesrefs,这是这 2 个操作系统的默认 ksh。祝你好运。 (不确定惠普)。

标签: shell unix solaris ksh


【解决方案1】:

ksh88 是 Solaris、HP-UX 和 AIX 中的默认 ksh。但是 ksh88 应该有可用的变量数组:

#/usr/bin/ksh
typeset -i cnt=0

yourarray[$cnt]='word1'
((cnt = cnt + 1))
yourarray[$cnt]='word666'

echo ${yourarray[0]}
word1

echo ${yourarray[1]}
word666

echo ${yourarray[2]}
    # nothing

【讨论】:

    猜你喜欢
    • 2012-04-22
    • 1970-01-01
    • 1970-01-01
    • 2011-04-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2010-11-19
    • 1970-01-01
    相关资源
    最近更新 更多