meta data for this page
  •  

差異處

這裏顯示兩個版本的差異處。

連向這個比對檢視

下次修改
前次修改
coding:bash [2019/04/02 07:00]
ghsrobert 建立
coding:bash [2019/04/05 22:31] (目前版本)
ghsrobert 欲學迴圈未果
行 1: 行 1:
 ====== Bash ====== ====== 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
 +  * 名稱可含字母、底線
 +  * 指定值用 ''='',__**但前後不可以有空格!**__/,(我的第一個習作就著了這個道啦……),/
 +  * 被引用時,名稱前面加 ''$''
 +    * 若要把 ''$'' 當一般符號用,就 ''\$'' 避掉
 +    * 若要和其他字元緊連,就用 ''${...}''
 +  * <span tip>可以引入執行命令傳回的結果</span>:''`...`'' 或 ''$(...)''\\ ↑這感覺好強大!:o<div ex><code bash>FILELIST=`ls`
 +FileWithTimeStamp=/tmp/my-dir/file_$(/bin/date +%Y-%m-%d).txt</code></div>((摘自 [[https://www.learnshell.org/en/Variables|Variables (learnshell.org)]]))
 +
 +<div tip>【目前進度】[[https://www.learnshell.org/en/Passing_Arguments_to_the_Script|Passing Arguments to the Script - Learn Shell Programming - Free Interactive Shell Programming Tutorial]]</div>
 +
 +==== 迴圈 ====
 +((20190405 為了實際應用的需要,跳過教程順序,超前學習 XD))
 +〔啊,LearnShell.org 的教程只介紹了不同種類 loop 的基本結構,沒有詳細說明啊〕
 +
 +==== 執行 ====
 +  * 賦予執行權限:<code bash>chmod a+x <腳本檔名></code>(([[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]]   * [[https://www.wikiwand.com/en/Bash_(Unix_shell)|Bash (Unix shell) - Wikiwand]]