数组的基本赋值 arr=(a b c) arr[index]=a 2.常用的两个方法 str=${arr[@]}(数组转化成字符串) len=${#arr[*]}(数组长度) 3.遍历数组的方法 #!/bin/bash arr=(a b c def vivi) i= len=${#arr[*]} while [ $i -lt $len ] do echo ${arr[$i]} done ;i<$len;i=$i+)) do echo ${arr[$i]} done #!/bin/bash arr…
shell中比如比较字符串.判断文件是否存在及是否可读等,通常用"[]"来表示条件测试. 注意:这里的空格很重要.要确保方括号的空格. if ....; then python中的条件判断: if ....: (此处是冒号,不同于shell的分号) .... (由于强制缩进,所以不需要 fi) .... (python时注意必须缩进四个字符) elif ....; then …
编程语言中都有条件判断,shell编程也不例外,下面我们来看一下shell中应该怎么使用if条件判断 以下蓝色字体部分为Linux命令,红色字体的内容为输出的内容: # cd /opt/scripts # vim script07.sh 开始编写script07.sh的脚本,脚本内容为: #! /bin/sh if [ 3 -gt 2 ] then echo "3>2" fi if [ 3 -lt 2 ] then echo "3<2" else ech…