linux grep egrep fgrep bash条件判断 bash测试 if 条件判断

简介:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
1.grep中的位置锚定,用于指定字符出现的位置
     ^ 锚定行首,^char
     
     $ 锚定行尾,char$
     
     ^$ 空白行
     
     \< char  锚定词首=\bchar
     
     char\> 锚定词尾=char\b
     
     grep分组
     \( \ )
     \(ab\)*xy  表示ab出现任意次,包括0次
     
     grep引用
         \1 后向引用,引用前面的第一个左括号以及与之对应的右括号中的模式所匹配的内容。
         \2
         ...
         \(a.b\)xy\1  eg: abbxyabb
         
 
2.grep常用选项
     -v:显示不能被模式匹配到的行
     -o:仅显示被模式匹配到的字符串而非整形
     -i:不区分大小写
     -E:支持扩展的正则表达式
     -A:
     -B:
     -C:
     
     
3.egrep 相当于grep -E
     使用扩展正则表达式来构建模式相当于grep -E
         . 任意单个字符
         [ ] 指定范围内任意单个字符 
         [^] 指定范围外任意单个字符
     
     匹配次数
         *
        
         +:匹配前面字符至少一次
         {m} 匹配前面字符m次
         {m,n} 匹配前面字符至少m次,至多n次
         {m,} 匹配前面字符至少m次
         {0,n} 匹配前面字符至多n次
         
      egrep中位置锚定
          ^ 行首
          $ 行尾
          \< = \b 锚定词首
          \> = \b 锚定词尾
          
      egrep分组 
          () 分组
            |  或者
            
4.fgrep : fast 不解析正则表达式
 
5.bash编程条件判断
     条件判断的常用判断类型
         整数测试
         文件测试
         字符测试
         
         $?
             0    表示测试正确
             1-255    表示错误
             
         布尔值 (真、假)
         逻辑运算
            
            
             非     
             
6.bash测试
     test EXPRESSION    
         [EXPRESSION]
         `EXPRESSTION`
         
7.bash中条件判断使用if
     单分支
         if 条件; then
             分支1 ;
         fi
         
     双分支
         if 条件; then
             分支1 ;
         else
             分支2 ;
         fi
              
      多分支
          if 条件; then
              分支1 ;
          elif
              分支2 ;
          elif
              分支3 ;
          ...
          else
              分支n ;
          fi

 













本文转自wanglm51051CTO博客,原文链接: http://blog.51cto.com/studyit2016/1774940,如需转载请自行联系原作者




相关文章
|
4月前
|
Linux Shell
linux自动崩溃,模拟测试
该脚本创建一个 systemd 服务和定时器,在系统启动3分钟后触发崩溃。通过向 /proc/sysrq-trigger 写入 &quot;c&quot; 来实现内核崩溃,用于测试系统崩溃后的恢复机制。
118 4
|
1月前
|
SQL 安全 Linux
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
110 1
Metasploit Pro 4.22.8-20251014 (Linux, Windows) - 专业渗透测试框架
|
1月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
178 1
Metasploit Framework 6.4.95 (macOS, Linux, Windows) - 开源渗透测试框架
|
2月前
|
安全 Linux 网络安全
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
269 2
Metasploit Pro 4.22.8-2025091701 (Linux, Windows) - 专业渗透测试框架
|
2月前
|
Linux 网络安全 iOS开发
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
374 1
Metasploit Framework 6.4.90 (macOS, Linux, Windows) - 开源渗透测试框架
|
2月前
|
安全 Linux 网络安全
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
Metasploit Framework 6.4.88 (macOS, Linux, Windows) - 开源渗透测试框架
540 0
|
3月前
|
运维 Linux 开发者
Linux系统中使用Python的ping3库进行网络连通性测试
以上步骤展示了如何利用 Python 的 `ping3` 库来检测网络连通性,并且提供了基本错误处理方法以确保程序能够优雅地处理各种意外情形。通过简洁明快、易读易懂、实操性强等特点使得该方法非常适合开发者或系统管理员快速集成至自动化工具链之内进行日常运维任务之需求满足。
231 18
|
2月前
|
存储 安全 Linux
Kali Linux 2025.3 发布 (Vagrant & Nexmon) - 领先的渗透测试发行版
Kali Linux 2025.3 发布 (Vagrant & Nexmon) - 领先的渗透测试发行版
514 0
|
安全 Linux 测试技术
OpenText Static Application Security Testing (Fortify) 25.3 (macOS, Linux, Windows) - 静态应用安全测试
OpenText Static Application Security Testing (Fortify) 25.3 (macOS, Linux, Windows) - 静态应用安全测试
214 0
|
2月前
|
缓存 安全 Linux
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
Metasploit Pro 4.22.8-2025082101 (Linux, Windows) - 专业渗透测试框架
167 0