- 第一行
#!/bin/bash
- 读取命令并保存到变量:
dir=\
pwd`或者dir=$(pwd)` - 数组:
array=(v1 v2 ... vn)
空格隔开
$ A=(this is an example of shell script)
$ echo ${A[0]} ${A[2]} ${A[3]} ${A[6]}
this an example script
$ echo ${A[8]}
$ echo ${A[*]}
this is an example of shell script
$ echo ${#A[*]}
7
推荐:
array=(
v1
v2
v3
)
- 遍历数组
for item in ${array[@]}; # ${}里面不能有空格
do
# bulabula
done
网友评论