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
posted @ 2018-12-05 19:59  TBHacker  阅读(139)  评论(0编辑  收藏  举报