一些经常看不懂,要反复看才会明白的命令、语法

1. 重定向功能中的怪异符号

1.1. >&2 

也就是把结果输出到和标准错误一样;之前如果有定义标准错误重定向到某file文件,那么标准输出也重定向到这个file文件。

其中&的意思,可以看成是“The same as”、“与...一样”的意思

答案来源:https://askubuntu.com/questions/1182450/what-does-2-mean-in-a-shell-script

1.2.

  1. 2>&1 means that stderr is redirected to stdout
  2. 3>&- means that file descriptor 3, opened for writing(same as stdout), is closed.

答案来源:https://stackoverflow.com/questions/14066992/what-does-minus-mean-in-exec-3-and-how-do-i-use-it

1.3.

&>file  意思是把标准输出 和 标准错误输出 都重定向到文件file中

答案来源:https://blog.csdn.net/u011630575/article/details/52151995

1.4.

> file redirects stdout to file
1> file redirects stdout to file

2> file redirects stderr to file

&> file redirects stdout and stderr to file (比较新的语法,在老系统上可能用不了)
> file 2>&1 redirects stdout and stderr to file (比较老的语法,现在仍然可以在新系统上用)

答案来源:https://askubuntu.com/questions/350208/what-does-2-dev-null-mean

 

2.

2.1. awk  一个强大的文本分析工具    https://www.runoob.com/linux/linux-comm-awk.html

 

3. bash脚本中一些常见但难懂的玩意儿

3.1. eval   该命令后面所跟的内容都认为是参数,但是会两次扫描其参数,第一次扫描会将参数中的变量进行替换,第二
次扫描会将后面的参数当作一个shell中的命令组合来执行命令。

3.2. exec   类似与eval,source,但是不同的是exec执行后面的命令后会替换当前的shell进程,而前两者不会。(NOTE:感觉跟系统调用的exec有点像)

    一旦执行exec,则跟在exec后面的命令就不会再执行了,而eval, source, bash等方法在执行完子shell之后,后面的命令依然会执行。(TODO:似乎当exec用于重定向文件描述符的时候,后边的命令会继续执行)

参考来源:https://blog.csdn.net/weixin_34327223/article/details/93059052

 

4. unix文本浏览器中的功能

4.1. 精准搜索功能:先按‘/’,随后输入\<要匹配的表达式\>

 

5. 进程替换(process substituion)

>(thing)  

The process substitution >(thing) will be replaced by a file name(actually, pathname, i guess). This file name corresponds to a file that is connected to the standard input of the thing inside the substitution.

答案来源 https://unix.stackexchange.com/questions/367849/why-is-there-a-dev-fd-63-in-the-output-of-echo-123-cat

 

6. 一些尚未熟悉的命令(TODO)

  • 文本处理 -  awksedcuttr
  • 正则表达式
  • 系统监控 - jobspstopkillfreedmesglsof

 

posted @ 2022-02-21 21:57  yinhuachen  阅读(54)  评论(0编辑  收藏  举报