backup &echo $! > shell.pidwhile [ -d /proc/`echo shell.pid` ];do sleep 5done
方便备份完成后继续接下去的脚本
- $*保存了以$IFS指定的分割符所分割的字符串组。
- $@原样保存了参数列表,也就是"$1""$2"...
$0代表脚本(命令)本身
$1,$2....带表第几个参数
1 #!/bin/bash
2 # patt-matching.sh
3
4 # 使用# ## % %%来进行参数替换操作的模式匹配.
5
6 var1=abcd12345abc6789
7 pattern1=a*c # * (通配符) 匹配 a - c 之间的任何字符.
8
9 echo
10 echo "var1 = $var1" # abcd12345abc6789
11 echo "var1 = ${var1}" # abcd12345abc6789
12 # (alternate form)
13 echo "Number of characters in ${var1} = ${#var1}"
14 echo
15
16 echo "pattern1 = $pattern1" # a*c (everything between 'a' and 'c')
17 echo "--------------"
18 echo '${var1#$pattern1} =' "${var1#$pattern1}" # d12345abc6789
19 # 最短的可能匹配, 去掉 abcd12345abc6789 的前 3 个字符
20 # |-| ^^^
21 echo '${var1##$pattern1} =' "${var1##$pattern1}" # 6789
22 # 最远的匹配,去掉 abcd12345abc6789 的前 12 个字符.
23 # |----------| ^^^^
24
25 echo; echo; echo
26
27 pattern2=b*9 # 'b' 到'9'之间的任何字符
28 echo "var1 = $var1" # 还是 abcd12345abc6789
29 echo
30 echo "pattern2 = $pattern2"
31 echo "--------------"
32 echo '${var1%pattern2} =' "${var1%$pattern2}" # abcd12345a
# 最近的匹配, 去掉 abcd12345abc6789 的最后 6 个字符
33
34 # |----| ^^^^
35 echo '${var1%%pattern2} =' "${var1%%$pattern2}" # a
36 # 最远匹配, 去掉 abcd12345abc6789 的最后 12 个字符
37 # |-------------| ^^^^^^
38
39 # 记住, # 和## 从字符串的左边开始,并且去掉左边的字符串,
40 # % 和 %% 从字符串的右边开始,并且去掉右边的子串.
1 #!/bin/bash
2 # var-match.sh:
3 # 对字符串的前后缀使用匹配替换的一个样本
4
5 v0=abc1234zip1234abc # 原始变量.
6 echo "v0 = $v0" # abc1234zip1234abc
7 echo
8
9 # 匹配字符串的前缀
10 v1=${v0/#abc/ABCDEF} # abc1234zip1234abc
11 # |-|
12 echo "v1 = $v1" # ABCDEF1234zip1234abc
13 # |----|
14
15 # 匹配字符串的后缀
16 v2=${v0/%abc/ABCDEF} # abc1234zip123abc
17 # |-|
18 echo "v2 = $v2" # abc1234zip1234ABCDEF
19 # |----|
20
21 echo
22
23 # ----------------------------------------------------
24 # 必须在开头或结尾匹配,否则,
25 #+ 将不会产生替换结果.
26 # ----------------------------------------------------
27 v3=${v0/#123/000} # 匹配上了,但不是在字符串的开头
28 echo "v3 = $v3" # abc1234zip1234abc
29 # 没替换.
30 v4=${v0/%123/000} # 匹配上了,但不是在字符串结尾.
31 echo "v4 = $v4" # abc1234zip1234abc
32 # 没替换.
33
34 exit 0
阅读(772) | 评论(0) | 转发(0) |