问题:
目标板使用rt5350芯片,在目标板的shell脚本中要实现计数功能,但是不能使用declare -i idx和let语句。
解决办法:
1. 考虑使用expr运算符来计算。
#!/bin/sh
idx=0
List="1 2 3"
### while [ $idx -lt 5 ]
for j in $List
do
#here do something
if [ $idx -eq 2 ]; then
echo "This is sequence no $idx"
fi
# space is neccessary
idx=`expr $idx + 1`
echo $idx
done
运算结果如下:
u1204@u1204-zhw:~/wrk/tmp/cpp_src/sh_exer$ sh test_cnt.sh
1
2
This is sequence no 2
3
u1204@u1204-zhw:~/wrk/tmp/cpp_src/sh_exer$使用expr解决了不能使用bash中的declare功能的不足。

本文介绍了一种在使用RT5350芯片的目标板上实现计数功能的方法,通过shell脚本和expr运算符替代了declare和let等不可用的指令。
9889

被折叠的 条评论
为什么被折叠?



