本文介绍了如何扭转KSH字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请帮我解决这个问题,我有一个数组女巫包括1000线,数量的,视为字符串,我要为所有的人由一个扭转他们的,我的问题是如何扭转他们,因为我有使用KSH或者使用bash或某事会这么容易.....我现在是这样的,但转=$ REV $ {副本:$ Y:1}中的ksh
不起作用。
I = 0
而[[$ I -lt 999]
做
REV =
VAR = $ {xnumbers [$ i]}
副本= $ {VAR}
LEN = $ {#}副本
Y = $(表达式$ LEN - 1)
而[[$ Y -ge 0]
做
REV =$ REV $ {副本:$ Y:1}
回声Y =$ Y
Y = $(表达式$ Y - 1)
DONE 回声我=$ I
回声REV =$ REV
#xnumbers [$ i] = $(表达式$ xnumbers [$ i]|$ REV)
回声XUM =$ {xnumbers [$ i]}
回声##############################################
I = $(表达式$ I + 1)
DONE
解决方案
我不知道为什么我们不能使用内置的REV功能。
$ 798回声|转
897
您也可以尝试:
$ 798回声| AWK'{为(i =长度; I = 0;!我 - )X = X SUBSTR($ 0,I,1);} END {打印X}
897
please help me with this problem, i have an array witch includes 1000 lines with number which are treated as strings and i want for all of them to reverse them one by one, my problem is how to reverse them because i have to use ksh or else with bash or something it would be so easy..... what i have now is this, but rev="$rev${copy:$y:1}"
doesnt work in ksh.
i=0
while [[ $i -lt 999 ]]
do
rev=""
var=${xnumbers[$i]}
copy=${var}
len=${#copy}
y=$(expr $len - 1)
while [[ $y -ge 0 ]]
do
rev="$rev${copy:$y:1}"
echo "y = " $y
y=$(expr $y - 1)
done
echo "i = " $i
echo "rev = " $rev
#xnumbers[$i]=$(expr $xnumbers[$i] "|" $rev)
echo "xum = " ${xnumbers[$i]}
echo "##############################################"
i=$(expr $i + 1)
done
解决方案
I am not sure why we cannot use built in rev function.
$ echo 798|rev
897
You can also try:
$ echo 798 | awk '{ for(i=length;i!=0;i--)x=x substr($0,i,1);}END{print x}'
897
这篇关于如何扭转KSH字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!