抓取github最新軟體版本
這裡以抓取frp為例
#!/bin/bash
frp_version=$(wget --no-check-certificate -qO- https://api.github.com/repos/fatedier/frp/releases | grep -o '"tag_name": ".*"' |head -n 1| sed 's/"//g;s/v//g'| sed 's/tag_name: //g')
echo ${frp_version}
程式碼解釋
抓取網頁程式碼
wget --no-check-certificate -qO- https://api.github.com/repos/fatedier/frp/releases
過濾掉除了tag_names那行的內容
grep -o '"tag_name": ".*"'
顯示結果
"tag_name": "v0.20.0" "tag_name": "v0.19.1" "tag_name": "v0.19.0" "tag_name": "v0.18.0" "tag_name": "v0.17.0" "tag_name": "v0.16.1" "tag_name": "v0.16.0" "tag_name": "v0.15.1" "tag_name": "v0.15.0" "tag_name": "v0.14.1" "tag_name": "v0.14.0" "tag_name": "v0.13.0" "tag_name": "v0.12.0" "tag_name": "v0.11.0" "tag_name": "v0.10.0" "tag_name": "v0.9.3" "tag_name": "v0.9.2" "tag_name": "v0.9.1" "tag_name": "v0.9.0" "tag_name": "v0.8.1" "tag_name": "v0.8.0" "tag_name": "v0.7.0" "tag_name": "v0.6.0" "tag_name": "v0.5.0" "tag_name": "v0.3.0" "tag_name": "v0.2.0" "tag_name": "v0.1.0"
重新排列順序,只顯示數字最大那行
head -n 1
顯示結果
"tag_name": "v0.20.0"
搜尋雙引號,並去除雙引號
sed 's/"//g;s/v//g'
顯示結果
tag_name: 0.20.0
搜尋tag_name: ,並去除tag_name
sed 's/tag_name: //g'
顯示結果
0.20.0
結論就是不斷的過濾,再將程式碼透過 | 傳送給下一段指令進行更精細的過濾