Skip to content

Latest commit

 

History

History
48 lines (36 loc) · 883 Bytes

File metadata and controls

48 lines (36 loc) · 883 Bytes

Shell Script

基本說明

  • 變數要用$表示
  • $0$1 表示command line傳入的參數

迴圈

  • {1..10}表示從1~10
  • do ... done 的裡面會執行程式
for i in {1..10}
do 
 echo $i
done
// 1,2,3,4,5,6,7,8,9,19

迴圈如果會用到「變數」要改用seq

for i in $(seq 1 $1)
do
  touch $i.js;
  echo $i
done
// 輸入3,可以產生1.js,2.js,3.js檔案

爬蟲

  • curl:可以用來獲取網站
  • pup: pup is a command line tool for processing HTML
curl  https://github.com/$1 | \
      pup  'span.vcard-fullname,'\
            'div.js-user-profile-bio,'\
            'span.p-label,'\
            'a[rel="nofollow me"] text{}'

執行shell Script

  • $ ./test.sh 或是 sh test.sh
  • 第一種方法要用chmod +x test.sh更改權限(ll可以看到權限)