if结构 #!/bin/env bash -gt ] then echo "$1 is positive" -lt ] then echo "$1 is negative" else echo "$1 is zero" fi while读取文件 while read aa do echo "$aa" done < aaa.s 数字比较 #等于 $num1 -eq $num2 #不等于 $num1 -ne $num2 #小…
.从文件读取 while read line do echo "line=$line" done < file.txt .将字符串转换为数组,并进行遍历 str="html, css, javascript, java, php, go, python" arr=(${str//,/ }) for item in ${arr[@]} do echo "item=$item" done .将目录转换为字符串 ls | xargs -d'\t'…
Linux shell脚本编程(二) 练习:求100以内所有偶数之和; 使用至少三种方法实现; 示例1: #!/bin/bash # declare -i sum=0 #声明一个变量求和,初始值为0 for i in $(seq 0 2 100); do sum=$(($sum+$i)) done echo "Even sum: $sum." 示例2: #!/bin/bash # declare -i sum=0 for i in {1..100}; do if [ $[$i%2] -…