2.倒序输出字符串
#!/bin/bash
while :
do
read -p "输入一个字符串:" str
if [ "$str" = "" ];
then
echo "error"
exit
fi
len=${#str}
res=
for ((i = $len;i>=0;i--))
do
res=$res${str:$i:1}# 利用字符切片从后往前一次取出一个字符并连接
done
echo "$res"
done
2.倒序输出字符串
#!/bin/bash
while :
do
read -p "输入一个字符串:" str
if [ "$str" = "" ];
then
echo "error"
exit
fi
len=${#str}
res=
for ((i = $len;i>=0;i--))
do
res=$res${str:$i:1}# 利用字符切片从后往前一次取出一个字符并连接
done
echo "$res"
done