1.给Bash中的function传递参数
搜索关键字:
- http://search.aol.com/aol/search?q=bash+function+parameter+site%3Astackoverflow.com
- http://search.aol.com/aol/search?q=bash+function+parameters+scripts+argument
相关链接:
- http://stackoverflow.com/questions/255898/how-to-iterate-over-arguments-in-bash-script
- http://stackoverflow.com/questions/16461656/bash-how-to-pass-array-as-an-argument-to-a-function
- http://www.ibm.com/developerworks/library/l-bash-parameters/
- http://bash.cyberciti.biz/guide/Pass_arguments_into_a_function
- http://stackoverflow.com/questions/3811345/how-to-pass-all-arguments-passed-to-my-bash-script-to-a-function-of-mine #推荐使用双引号括住”$@”
- http://stackoverflow.com/questions/2740906/in-bash-how-do-you-access-command-line-arguments-inside-a-function
函数名 “$@” #将Bash脚本的参数传给指定函数(使用双引号括起来)
拓展链接:
- Complex Functions and Function Complexities
- http://tldp.org/LDP/abs/html/functions.html
- http://stackoverflow.com/questions/6212219/passing-parameters-to-a-bash-function
- http://stackoverflow.com/questions/3190818/pass-all-arguments-from-bash-script-to-another-command
- http://stackoverflow.com/questions/8514284/bash-how-to-pass-arguments-to-a-script-that-is-read-via-standard-input
- http://tldp.org/HOWTO/Bash-Prog-Intro-HOWTO.html
2.Bash中的if-elif-else语句
搜索关键字:
http://search.aol.com/aol/search?q=bash+if+elif
样例讲解:
- http://www.thegeekstuff.com/2010/06/bash-if-statement-examples/
- http://ixyzero.com/blog/archives/1225.html #表达式、字符串、数字的比较
3.在Bash中获取当前脚本名的方法
SCRIPT="`readlink -e $0`" #脚本名称 SCRIPTPATH="`dirname $SCRIPT`" #脚本所在目录(绝对路径) {basename、dirname、readlink、realpath}
4.alias中的转义
用历史命令的Top10来做个演示:
alias top11="history | awk '{\$1=\$2=\"\";a[\$0]++} END{for(i in a){print a[i]\"\t\"i}}' | sort -rn | head" alias top10="history | awk '{a[\$3]++} END{for(i in a){print a[i]\"\t\"i}}' | sort -rn | head"
说明:因为我将history命令的格式改成了第3列是具体的命令,所以上面的awk取的是$3,而不是通常的$2。
参考链接:
- http://unix.stackexchange.com/questions/159569/how-to-escape-single-quotes-correctly-creating-an-alias
- http://stackoverflow.com/questions/7254509/how-to-escape-single-quotes-in-bash-grep
- http://stackoverflow.com/questions/4761242/escaping-a-parenthesis-in-grep-ack
- http://stackoverflow.com/questions/1250079/escaping-single-quotes-within-single-quoted-strings
- http://stackoverflow.com/questions/20111063/bash-alias-command-with-both-single-and-double-quotes
5.使用Linux命令查找两个文件中的不同之处
搜索关键字:
http://cn.bing.com/search?q=find+different+between+files
参考链接:
comm -3 <(sort file1) <(sort file2) | sed 's/^\t//' awk '{count[$0]++} END {for (line in count) if (count[line] == 1) print line}' file1 file2 grep -vf file1 file2 # grep -vf file2 file1 diff file1 file2
《 “Bash的知识点总结_1” 》 有 4 条评论
Bash编码的一些技巧
https://jvns.ca/blog/2017/03/26/bash-quirks/
bash-handbook-zh-CN(谨以此文档献给那些想学习Bash又无需钻研太深的人)
https://github.com/denysdovhan/bash-handbook/blob/master/translations/zh-CN/README.md
30 个方便的 Bash shell 别名 | Linux 中国
https://mp.weixin.qq.com/s/RZLdEPmeYVWL1Q6LvD6NzQ
https://www.cyberciti.biz/tips/bash-aliases-mac-centos-linux-unix.html
`
◈ bash alias 的那些事
◈ 如何列出 bash 别名
◈ 如何定义或者创建一个 bash shell 别名
◈ 如何临时性地禁用 bash 别名
◈ 如何删除 bash 别名
◈ 如何让 bash shell 别名永久生效
◈ 关于特权权限判断
◈ 定义与操作系统类型相关的别名
◈ 30 个 bash shell 别名的案例
`
译 | 关于bash函数你不知道的一些事情
http://www.techug.com/post/bash-functions.html
http://www.catonmat.net/blog/bash-functions/