Bash的知识点总结_1


1.给Bash中的function传递参数
搜索关键字:
相关链接:

函数名 “$@”    #将Bash脚本的参数传给指定函数(使用双引号括起来)

拓展链接:
2.Bash中的if-elif-else语句
搜索关键字:

http://search.aol.com/aol/search?q=bash+if+elif

样例讲解:
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。

参考链接:
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 条评论

  1. 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 别名的案例
    `

回复 hi 取消回复

您的电子邮箱地址不会被公开。 必填项已用*标注