遍历目录下所有的文件是目录还是文件 for file in ./* do if test -f $file then echo $file 是文件 fi if test -d $file then echo $file 是目录 fi done filelist=`ls ./proto` echo $filelist for file in $filelist;do #不能有判断if [-f $file ] ,为什么?因为文件是在当前目录的proto目录下,我们filelist输出的是文件列表,没…
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] -…