shell 数组【了解一下】
数组编程
#!/bin/bash
# array
soft=(
php
mysql
nginx
)
# 输出第一个
echo ${soft[0]}
# 输出所有
echo "This soft total ${soft[@]}"
# 输出数量
echo "This soft count ${#soft[@]}"
# 删除一个元素
unset soft[2]
echo "This soft total ${soft[@]}"
# 临时替换
echo ${soft[@]/php/java}
echo "This soft total ${soft[@]}"
运行结果
# /bin/bash array.sh
php
This soft total php mysql nginx
This soft count 3
This soft total php mysql
java mysql
This soft total php mysql