owned this note changed 7 years ago
Linked with GitHub

看懂源碼基礎 - 批次檔除錯及排版工具 - Daniel Lin 林原志

歡迎來到 https://hackmd.io/c/COSCUP2018 共筆

Image Not Showing Possible Reasons
  • The image file may be corrupted
  • The server hosting the image is unavailable
  • The image path is incorrect
  • The image format is not supported
Learn More →

點擊本頁上方的 開始用 Markdown 一起寫筆記!
手機版請點選上方 按鈕展開議程列表。

講者提供的講義: https://github.com/dlintw/coscup2018/blob/master/readshell/read_shell_scripts.rst

Speaker

Daniel Lin

簡介

(講者一開始就把筆記準備好給大家之後拿去用!)

潮讚der,直接整理好筆記,佛心講者 d(`・∀・)b
等等若講者有提供連結會補上,目前講者是show本機上的HTML file

範例 -> reflector.sh

  • reflector.sh 是一個將Arch Linux download mirrors依照存取速度排序的工具

提醒: chmod +x 可以讓指令直接能被執行,相應的執行程式會被定義在檔案第一行,例如 #!bash

  • 建議編寫shell script時使用有syntax highlight的編輯器,至少保留字會被換顏色,確保沒有筆誤

如何分辨指令是不是 bash 內建的?「command -v bash」這種會給出來源的就不是,「command -v if」這種給不出來源的就是。

Pipeline

curl -LksS -o - 'https://www.archlinux.org/mirrors/status/json' \
   | sed 's,{,\n{,g' \
   | sed -n '/rsync/d; /pct": 1.0/p' \
   | .....

Useful vim plugin VOoM

#{{{1

舊版用倒單引號執行,新版建議用$()執行指令。

Tool: shellcheck

Tool: 排版工具 shfmt

How to prevent writing a wrong shell?

  • set -euo pipefail
  • vim plugin

除錯

# not complete...
PS4='+\y $BASH_SOURCE:$LINENO: ${function}'
tags: COSCUP2018 source
Select a repo