Skip to content
Ricky
Chinese

搜尋

Searching… No matching pages. Matching pages are listed below. Search is unavailable. Please try again.

SHELL

All posts

在 bash 腳本中使用 here-doc 將資料寫入檔案 使用 EOF<<- 讓 here-doc 在 shell 腳本中可自然縮排 command <<-EOF msg1 msg2 $var on line EOF 使用 'EOF' 停用路徑/參數/變數展開、命令替換與算術展開 #!/bin/bash OUT=/tmp/output.txt echo "Starting my script..." echo …

1 分鐘

Bash 腳本如何建立臨時檔案:mktemp 與 trap 教學 mktemp 命令 產生的臨時檔案名稱是隨機的,而且權限只有使用者本人可讀寫。 為了確保臨時檔案建立成功,mktemp 後面最好使用 OR 運算子(||),在建立失敗時退出腳本。 為了確保腳本退出時刪除臨時檔案,可以使用 trap 指定退出時的清理動作。 #!/bin/bash trap 'rm -f "$TMPFILE"' EXIT …

1 分鐘

Shell 腳本學習筆記 執行算術運算 val=`expr $a + $b` 運算符 符號 說明 示例 ! 非運算 [ ! false ] -o 或運算 [ $a -lt 20 -o $b -gt 20 ] -a 與運算 [ $a -lt 20 -a $b -gt 20 ] = 相等檢測 [ $a = $b ] != 不相等檢測 [ $a != $b ] -z 字串長度是否為 0,為 0 則回傳 true [ -z …

2 分鐘

Shell 中 < <(command args) 是什麼意思? while IFS= read -r -d $'\0' file; do dosomethingwith "$file" # 對每個檔案進行處理 done < <(find /bar -name *foo* -print0) <() 在手冊中稱為 process substitution,它類似於管線,但會傳遞 /dev/fd/63 這種形式的參數, …

1 分鐘