所以我写了以下代码:
#!/bin/bash
echo "for loop"
names=("fulmetall" "alphonse" "flame alchemesit" "king bradely" "hoenheim")
a=0
while [ $a -lt 5 ];
do
echo ${names[$a]}
a=`expr a + 1`
done
并得到以下错误,而且我不知道为什么它不起作用。 名字会被打印,其他人不会。
for loop
fulmetall
expr: non-integer argument
./for_loop.sh: line 8: [: -lt: unary operator expected
答案 0 :(得分:1)
#!/bin/bash
echo "for loop"
names=("fulmetall" "alphonse" "flame alchemesit" "king bradely" "hoenheim")
a=0
while [ $a -lt 5 ];
do
echo ${names[$a]}
a=`expr $a + 1`
done