HP / SOL的等效排版-n选项

时间:2012-09-24 19:32:11

标签: shell unix solaris ksh

这是一个更大的脚本的简化部分。我使用i作为conter来循环一组字符串。

我有多个字符串“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盒子不喜欢排版n ...我能在这里做什么而不是-n用于HP或Solaris? 当我在我的盒子上运行nameref时,我得到nameref:not found

1 个答案:

答案 0 :(得分: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