====== Bash ====== ===== 教程 ===== * [[https://www.learnshell.org/|Learn Shell Programming - Free Interactive Shell Programming Tutorial]]/,(這次先找一個不是 Codecademy 的~感覺比較有效率?),/ ===== 要點 ===== ==== 基本 ==== * 第一行總是 ''#!/bin/bash'' = 宣告使用的 shell * echo * 字串可以用 ''%%'%%'' 括住 ← 只會留一個空格 * ''"..."'' 可以保留任何空格字元 * 註解:行首或行中 ''# ''((更深入介紹各種方法:[[https://stackoverflow.com/questions/1455988/commenting-in-a-bash-script|syntax - Commenting in a Bash script - Stack Overflow]])) ==== 變數 ==== * case-sensitive * 名稱可含字母、底線 * 指定值用 ''='',__**但前後不可以有空格!**__/,(我的第一個習作就著了這個道啦……),/ * 被引用時,名稱前面加 ''$'' * 若要把 ''$'' 當一般符號用,就 ''\$'' 避掉 * 若要和其他字元緊連,就用 ''${...}'' * 可以引入執行命令傳回的結果:''`...`'' 或 ''$(...)''\\ ↑這感覺好強大!:o
FILELIST=`ls`
FileWithTimeStamp=/tmp/my-dir/file_$(/bin/date +%Y-%m-%d).txt
chmod a+x <腳本檔名>
(([[https://stackoverflow.com/questions/5125907/how-to-run-a-shell-script-in-os-x-by-double-clicking/5126257|macos - How to run a shell script in OS X by double-clicking? - Stack Overflow]]))
* 在 macOS 中開啟:選擇用「終端機」
===== 參考 =====
* [[https://www.wikiwand.com/en/Bash_(Unix_shell)|Bash (Unix shell) - Wikiwand]]