一、定義數組
strArr = ("aaa" "bbb" "ccc")
二、數組遍歷
strArr=("aaa" "bbb" "ccc")
for i in ${strArr[@]};do
echo $i
done
result:
cactus:Desktop liruigao$ sh test.sh
aaa
bbb
ccc
三、日期
獲取昨天日期
yesterday=`date +%Y%m%d -d -1days`
日期遍歷
#!/bin/bash
datebeg=20200326
dateend=20200402
beg_s=`date -d "$datebeg" +%s`
end_s=`date -d "$dateend" +%s`
while [ "$beg_s" -le "$end_s" ]
do
handleDate=`date -d @$beg_s +%Y%m%d`
beg_s=$((beg_s+86400))
echo $handleDate
done
result:
20200326
20200327
20200328
20200329
20200330
20200331
20200401
20200402
四、不同文件內容取交、並集
取並集:
cat file1 file2 | sort | uniq > file3
取交集:
cat file1 file2 | sort | uniq -d > file3
取非交集:
cat file1 file2 | sort | uniq -u > file3