* [[http://linux.vbird.org/linux_basic/0320bash.php|第十章、認識與學習BASH]] * [[http://people.cs.nctu.edu.tw/~chenwj/slide/SA/ShellProgramming.new.pdf|Shell and Shell Programming]] * [[http://www.covingtoninnovations.com/mc/winforunix.html|Windows for UNIX Users]] * [[http://www.lemoda.net/windows/windows2unix/windows2unix.html|Windows and Unix command line equivalents]] # 以空白做區分,取出第六欄 $ grep TraceInit debug_panic_427.txt | cut -d " " -f 6 # 取匹配後的下一行 $ grep -A1 foo bar.txt # 將 stdin 當作後續指令的輸入 $ echo "foo" | xargs -0 -I {} rm -f {} * [[http://www.linuxtutorialblog.com/post/tutorial-conditions-in-bash-scripting-if-statements|Tutorial: Conditions in bash scripting (if statements)]] * [[http://www.linuxjournal.com/content/bash-regular-expressions|Bash Regular Expressions]] if [ $(echo "$max < $val" | bc) -eq 1 ] ; then # DO SOMETHING else # DO SOMETHING fi * [[http://unstableme.blogspot.com/2008/06/bash-float-comparison-bc.html|Bash float comparison - bc]] * [[http://stackoverflow.com/questions/10383529/can-i-replace-the-array-name-in-a-bash-script|Can I replace the array name in a bash script?]] * [[http://www.linuxjournal.com/content/tech-tip-dereference-variable-names-inside-bash-functions|Tech Tip: Dereference Variable Names Inside Bash Functions]] * [[http://www.linuxjournal.com/content/bash-associative-arrays|Bash Associative Arrays]] * [[http://insights-into-software.blogspot.com/2010/03/elegant-parallel-processes-in-bash.html|Elegant parallel processes in bash]] * [[http://pebblesinthesand.wordpress.com/2008/05/22/a-srcipt-for-running-processes-in-parallel-in-bash/|A srcipt for running processes in parallel in Bash]] * [[http://www.linuxtopia.org/online_books/advanced_bash_scripting_guide/subshells.html|Chapter 20. Subshells]] ====== 範例 ====== * 計算目錄下各個目的檔所佔的 ROM 大小 (.text + .data)。 $ ls | xargs arm-none-eabi-size.exe | sed '1d' | awk '{sum = $1 + $2}; {print sum}' * [[http://unix.stackexchange.com/questions/96226/delete-first-line-of-a-file|Delete First line of a file]] * [[http://www.unix.com/unix-for-dummies-questions-and-answers/82810-how-get-nth-line-file-usuing-commands.html|How to get nth line from a file usuing commands]] * [[http://www.liamdelahunty.com/tips/linux_ls_awk_totals.php|Linux - Sum using awk]] * 修改目錄下 (包含子目錄) 檔案的權限。 $ find . -type f -exec chmod 644 {} + * [[http://askubuntu.com/questions/58467/chmod-files-only-in-all-subdirectories|chmod files only in all subdirectories]] * 批次修改目錄下的所有檔名。 # 將檔名中帶有 foo 的字串,替換成 bar。 $ for filename in *foo*; do mv "$filename" "${filename//foo/bar}"; done * [[http://www.peteryu.ca/tutorials/shellscripting/batch_rename|Batch rename files by finding and replacing terms in the filename]] ====== 常用工具 ====== * [[wp>cut]] * [[wp>sed]] * [[wp>awk]] * [[http://www.cyberciti.biz/faq/bash-scripting-using-awk/|How To Use awk In Bash Scripting]] * [[wp>xargs]] * [[https://sidvind.com/wiki/Xargs_by_example|Xargs by example]] * [[http://www.cyberciti.biz/faq/linux-unix-bsd-xargs-construct-argument-lists-utility/|xargs: How To Control and Use Command Line Arguments]] ====== Q & A ====== * [[http://www.linuxdevcenter.com/pub/a/linux/lpt/09_22.html|xargs: Problems with Spaces and Newlines]] ====== 外部連結 ====== * [[http://tldp.org/LDP/Bash-Beginners-Guide/html/index.html|Bash Guide for Beginners]] * [[http://tldp.org/LDP/abs/html/index.html|Advanced Bash-Scripting Guide]] * [[http://www.ibm.com/developerworks/library/l-bash.html|Bash by example]] * [[http://wiki.bash-hackers.org/syntax/quoting|Quotes and escaping]] * 用雙引號將 Windows 路徑包起來,以當成字串處理。