shell腳本:一些常用命令

一、定義數組

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
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章