一、循环
1.列表的循环
list="111 222 333"
for id in ${list};
do
echo $id
done
2.文件内容的循环
2.1 按照回车或是tab分割文件内容
for id in $(cat /path/to/idFile)
do
echo $id
done
2.2 遍历文件每行
cat file | while read line
do
echo $line
done
3.数字的循环
for i in {1..5}
do
echo $i
done
4.遍历目录
for file in `ls`
do
echo $file
done
二、条件判断
str1=china usa
str2=japan
if [ ! -d "path/to" ];then #如果当前目录中不存在path/to目录
mkdir -p path/tp
elif [ -f file ];then #如果当前目录中存在文件file
echo 2
elif [ "${str1}" == china ];then #如果字符串str1等于china
echo 3
elif [ "${str2}" =~ an ];then $如果str2包含an
echo 4
else
echo 5
fi