How Linux Works:Shell 编程

摘要

  • Overview
  • BASIC
  • key words:echo、grep、awk、xargs
  • functions & parameters
  • user environment: crontabs
  • concurrent: threads
  • Application

Overview

When to Use Shell Scripts

Shell Script Basics

shell-startup

User Environments

Key Words

Echo

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
$ echo 'foo:123:bar:789' | awk -F: '{print $2,$3}'
123 bar

$ # second field where input field separator is :
$ echo 'foo:123:bar:789' | awk -F: '{print $2}'
123

$ # last field
$ echo 'foo:123:bar:789' | awk -F: '{print $NF}'
789

$ # first and last field
$ # note the use of , and space between output fields
$ echo 'foo:123:bar:789' | awk -F: '{print $1, $NF}'
foo 789

$ # second last field
$ echo 'foo:123:bar:789' | awk -F: '{print $(NF-1)}'
bar

$ # use quotes to avoid clashes with shell special characters
$ echo 'one;two;three;four' | awk -F';' '{print $3}'
three

$ echo 'Sample123string54with908numbers' | awk -F'[0-9]+' '{print $2}'
string

Grep

AWK

Xargs

Application

文本查找

1
$ grep -rn "Hello" *

Template

扩展阅读

电子书《Linux Perf Master》

扩展阅读:性能诊断指南

扩展阅读:How Linux Works

扩展阅读:动态追踪技术

参考文献

欢迎扫码关注微信公众号获取最新动态,读者交流 QQ 群:338272982 。

推荐文章