#!/bin/bash
ARRAY=('debian','ubuntu','fedora')
ELEMENTS=${#ARRAY[@]}
for ((i=0;i
echo ${ARRAY[${i}]}
done
-----
NOTE: there are double "(" and ")" after "for"
----
[jerry@localhost bin]$ ./array_test.sh
debian,ubuntu,fedora
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[jerry@localhost bin]$ cat array_test3.sh
#!/bin/bash
echo $1 $2 $3 ' -> ehco $1 $2 $3'
args=($@)
echo $args[1]
echo ${args[1]}[jerry@localhost bin]$ ./array_test3.sh 1 2 3
1 2 3 -> ehco $1 $2 $3
1[1]
2
==================[jerry@localhost bin]$ cat for_parameter.sh
#!/bin/bash
for ((i=0;i echo $i
done
[jerry@localhost bin]$ ./for_parameter.sh p1 p2 p3
0
1
2
==========
not correct!!!
ARRAY=('debian','ubuntu','fedora')
ELEMENTS=${#ARRAY[@]}
for ((i=0;i
echo ${ARRAY[${i}]}
done
-----
NOTE: there are double "(" and ")" after "for"
----
[jerry@localhost bin]$ ./array_test.sh
debian,ubuntu,fedora
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
[jerry@localhost bin]$ cat array_test3.sh
#!/bin/bash
echo $1 $2 $3 ' -> ehco $1 $2 $3'
args=($@)
echo $args[1]
echo ${args[1]}[jerry@localhost bin]$ ./array_test3.sh 1 2 3
1 2 3 -> ehco $1 $2 $3
1[1]
2
==================[jerry@localhost bin]$ cat for_parameter.sh
#!/bin/bash
for ((i=0;i echo $i
done
[jerry@localhost bin]$ ./for_parameter.sh p1 p2 p3
0
1
2
==========
not correct!!!
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/23895263/viewspace-697721/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/23895263/viewspace-697721/