forked from netkiller/netkiller.github.io
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvariable.html
More file actions
536 lines (433 loc) · 19.9 KB
/
Copy pathvariable.html
File metadata and controls
536 lines (433 loc) · 19.9 KB
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>1.3. variable</title><link rel="stylesheet" type="text/css" href="..//docbook.css" /><meta name="generator" content="DocBook XSL Stylesheets V1.79.1" /><meta name="keywords" content="shell,bash,zsh, awk,sed,curl,expect, grep,sort" /><link rel="home" href="../index.html" title="Netkiller Linux Shell 手札" /><link rel="up" href="index.html" title="第 1 章 Bash Shell" /><link rel="prev" href="introduction.html" title="1.2. Introduction" /><link rel="next" href="conditions.html" title="1.4. conditions if and case" /></head><body><a xmlns="" href="http://www.netkiller.cn/">Home</a> |
<a xmlns="" href="http://netkiller.github.io/">简体中文</a> |
<a xmlns="" href="http://netkiller.sourceforge.net/">繁体中文</a> |
<a xmlns="" href="/journal/index.html">杂文</a> |
<a xmlns="" href="/search.html">Search</a> |
<a xmlns="" href="http://netkiller-github-com.iteye.com/">ITEYE 博客</a> |
<a xmlns="" href="http://my.oschina.net/neochen/">OSChina 博客</a> |
<a xmlns="" href="https://www.facebook.com/bg7nyt">Facebook</a> |
<a xmlns="" href="http://cn.linkedin.com/in/netkiller/">Linkedin</a> |
<a xmlns="" href="https://zb.oschina.net/profile/725072/market">作品与服务</a> |
<a xmlns="" href="mailto:netkiller@msn.com">Email</a><div class="navheader"><table width="100%" summary="Navigation header"><tr><th colspan="3" align="center">1.3. variable</th></tr><tr><td width="20%" align="left"><a accesskey="p" href="introduction.html">上一页</a> </td><th width="60%" align="center">第 1 章 Bash Shell</th><td width="20%" align="right"> <a accesskey="n" href="conditions.html">下一页</a></td></tr></table><hr /></div><table xmlns=""><tr><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=watch&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&repo=netkiller.github.io&type=fork&count=true&size=large" height="30" width="170" frameborder="0" scrolling="0" style="width:170px; height: 30px;" allowTransparency="true"></iframe></td><td><iframe src="http://ghbtns.com/github-btn.html?user=netkiller&type=follow&count=true&size=large" height="30" width="240" frameborder="0" scrolling="0" style="width:240px; height: 30px;" allowTransparency="true"></iframe></td></tr></table><div class="section"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="variable"></a>1.3. variable</h2></div></div></div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="expression"></a>1.3.1. 表达式</h3></div></div></div>
<pre class="screen">
!!:再次执行上一条命令
!$:上一条命令的最后一个单词
{a..b}:按照从a到b顺序的一个数字列表
{a,b,c}:三个词a,b,c. 可以这样使用 touch /tmp/{a,b,c}
{$1-$9}:执行shell脚本时的命令行参数
$0:正在执行的命令名称
$#:当前启动的命令中传入的参数个数
$?:上一条命令的执行返回值。
$$:该shell的进程号。
$*:从$1开始,启动该shell脚本的所有参数。
</pre>
<pre class="screen">
$ mkdir -p {a..z}
$ ls
a b c d e f g h i j k l m n o p q r s t u v w x y z
$ mkdir -p {a..z}{0..9}
$ ls
a0 b0 c0 d0 e0 f0 g0 h0 i0 j0 k0 l0 m0 n0 o0 p0 q0 r0 s0 t0 u0 v0 w0 x0 y0 z0
a1 b1 c1 d1 e1 f1 g1 h1 i1 j1 k1 l1 m1 n1 o1 p1 q1 r1 s1 t1 u1 v1 w1 x1 y1 z1
a2 b2 c2 d2 e2 f2 g2 h2 i2 j2 k2 l2 m2 n2 o2 p2 q2 r2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 m8 n8 o8 p8 q8 r8 s8 t8 u8 v8 w8 x8 y8 z8
a9 b9 c9 d9 e9 f9 g9 h9 i9 j9 k9 l9 m9 n9 o9 p9 q9 r9 s9 t9 u9 v9 w9 x9 y9 z9
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="environment"></a>1.3.2. Internal Environment Variables</h3></div></div></div>
<a class="ulink" href="http://tldp.org/LDP/abs/html/internalvariables.html" target="_top">http://tldp.org/LDP/abs/html/internalvariables.html</a>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.set"></a>1.3.3. set 设置变量</h3></div></div></div>
<pre class="screen">
$ set -- `echo aa bb cc`
$ echo $1
aa
$ echo $2
bb
$ echo $3
cc
$ set -- aa bb cc
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="unset"></a>1.3.4. unset 变量销毁</h3></div></div></div>
<pre class="screen">
$ unset logfile
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.default"></a>1.3.5. 设置变量默认值</h3></div></div></div>
<p>如果 logfile 值已经存在侧不会覆盖</p>
<pre class="screen">
$ logfile=/var/log/test.log
$ echo $logfile
/var/log/test.log
$ logfile=${logfile:-/tmp/test.log}
$ echo $logfile
/var/log/test.log
</pre>
<p>如果变量为空才能设置</p>
<pre class="screen">
$ unset logfile
$ logfile=${logfile:-/tmp/test.log}
$ echo $logfile
/tmp/test.log
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.export"></a>1.3.6. export 设置全局变量</h3></div></div></div>
<pre class="screen">
export CATALINA_OUT=/www/logs/tomcat/catalina.out
</pre>
<p>unset 销毁变量</p>
<pre class="screen">
unset CATALINA_OUT
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.declare"></a>1.3.7. declare</h3></div></div></div>
<pre class="screen">
功能说明:声明 shell 变量。
语 法:declare [+/-][rxi][变量名称=设置值] 或 declare -f
补充说明:declare为shell指令,在第一种语法中可用来声明变量并设置变量的属性([rix]即为变量的属性),在第二种语法中可用来显示shell函数。若不加上任何参数,则会显示全部的shell变量与函数(与执行set指令的效果相同)。
参 数:
+/- "-"可用来指定变量的属性,"+"则是取消变量所设的属性。
-f 仅显示函数。
r 将变量设置为只读。
x 指定的变量会成为环境变量,可供shell以外的程序来使用。
i [设置值]可以是数值,字符串或运算式。
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.system"></a>1.3.8. 系统变量</h3></div></div></div>
<p>系统变量</p>
<pre class="screen">
Shell常用的系统变量并不多,但却十分有用,特别是在做一些参数检测的时候。下面是Shell常用的系统变量
表示方法 描述
$n $1 表示第一个参数,$2 表示第二个参数 ...
$# 命令行参数的个数
$0 当前程序的名称
$? 前一个命令或函数的返回码
$* 以"参数1 参数2 ... " 形式保存所有参数
$@ 以"参数1" "参数2" ... 形式保存所有参数
$$ 本程序的(进程ID号)PID
$! 上一个命令的PID
</pre>
<pre class="screen">
[root@cc tmp]# cat test.sh
echo $#
echo $@
[root@cc tmp]# ./test.sh helloworld
1
helloworld
</pre>
<pre class="screen">
其中使用得比较多得是 $n $# $0 $? ,看看下面的例子:
#!/bin/sh
if [ $# -ne 2 ] ; then
echo "Usage: $0 string file";
exit 1;
fi
grep $1 $2 ;
if [ $? -ne 0 ] ; then
echo "Not Found \"$1\" in $2";
exit 1;
fi
echo "Found \"$1\" in $2";
上面的例子中使用了$0 $1 $2 $# $? 等变量
下面运行的例子:
./chapter2.2.sh usage chapter2.2.sh
Not Found "usage" in chapter2.2.sh
-bash-2.05b$ ./chapter2.2.sh Usage chapter2.2.sh
echo "Usage: $0 string file";
Found "Usage" in chapter2.2.sh
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.number"></a>1.3.9. Numerical 数值运算</h3></div></div></div>
<p>数值运算表达式</p>
<pre class="screen">
$((EXPR))
</pre>
<p></p>
<pre class="screen">
echo $((1+1))
echo $((5*5))
</pre>
<pre class="screen">
num=$(awk "BEGIN {print $num1+$num2; exit}")
num=$(python -c "print $num1+$num2")
num=$(perl -e "print $num1+$num2")
num=$(echo $num1 + $num2 | bc)
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.strings"></a>1.3.10. Strings 字符串操作</h3></div></div></div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931726752"></a>1.3.10.1. ##/#</h4></div></div></div>
<pre class="screen">
$ MYVAR=foodforthought.jpg
$ echo ${MYVAR##*fo}
rthought.jpg
$ echo ${MYVAR#*fo}
odforthought.jpg
</pre>
<p>一个简单的脚本例子</p>
<pre class="screen">
mytar.sh
#!/bin/bash
if [ "${1##*.}" = "tar" ]
then
echo This appears to be a tarball.
else
echo At first glance, this does not appear to be a tarball.
fi
$ ./mytar.sh thisfile.tar
This appears to be a tarball.
$ ./mytar.sh thatfile.gz
At first glance, this does not appear to be a tarball.
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931724272"></a>1.3.10.2. %%/%</h4></div></div></div>
<pre class="screen">
$ MYFOO="chickensoup.tar.gz"
$ echo ${MYFOO%%.*}
chickensoup
$ echo ${MYFOO%.*}
chickensoup.tar
MYFOOD="chickensoup"
$ echo ${MYFOOD%%soup}
chicken
</pre>
<pre class="screen">
$ test="aaa bbb ccc ddd"
$ echo ${test% *}
aaa bbb ccc
$ echo ${test%% *}
aaa
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931722288"></a>1.3.10.3. :n1:n2</h4></div></div></div>
<p>:${varible:n1:n2}:截取变量varible从n1到n2之间的字符串。</p>
<pre class="screen">
$ EXCLAIM=cowabunga
$ echo ${EXCLAIM:0:3}
cow
$ echo ${EXCLAIM:3:7}
abunga
file=netkiller.rpm
$echo ${file: -3}
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931720336"></a>1.3.10.4. #</h4></div></div></div>
<p>:${varible:n1:n2}:截取变量varible从n1到n2之间的字符串。</p>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931718944"></a>1.3.10.5. example</h4></div></div></div>
<pre class="screen">
$cat name.sh
#!/bin/bash
while read line ; do
fistname=${line% *}
lastname=${line#* }
echo $fistname $lastname
done <<EOF
neo chen
jam zheng
EOF
$ bash name.sh
neo chen
jam zheng
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="string.len"></a>1.3.10.6. 计算字符串长度</h4></div></div></div>
<p>计算字符串长度</p>
<pre class="screen">
echo ${#PATH}
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931715168"></a>1.3.10.7. 字符串查找替换</h4></div></div></div>
<pre class="screen">
# str="1 2 3 4";echo ${str// /}
1234
# str="1 2 3 4";echo ${str// /,}
1,2,3,4
# str="1 2 3 4";echo ${str// /+}
1+2+3+4
# str="neo netkiller";echo ${str//neo/hello}
hello netkiller
</pre>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="variable.array"></a>1.3.11. Array 数组</h3></div></div></div>
<p>定义数组</p>
<pre class="screen">
arr=(Hello World)
arr[0]=Hello
arr[1]=World
</pre>
<p>访问数组</p>
<pre class="screen">
echo ${arr[0]} ${arr[1]}
${arr[*]} # All of the items in the array
${!arr[*]} # All of the indexes in the array
${#arr[*]} # Number of items in the array
${#arr[0]} # Length of item zero
</pre>
<p>追加操作</p>
<pre class="screen">
ARRAY=()
ARRAY+=('foo')
ARRAY+=('bar')
</pre>
<pre class="screen">
#!/bin/bash
array=(one two three four [5]=five)
echo "Array size: ${#array[*]}"
echo "Array items:"
for item in ${array[*]}
do
printf " %s\n" $item
done
echo "Array indexes:"
for index in ${!array[*]}
do
printf " %d\n" $index
done
echo "Array items and indexes:"
for index in ${!array[*]}
do
printf "%4d: %s\n" $index ${array[$index]}
done
</pre>
<pre class="screen">
#!/bin/bash
array=("first item" "second item" "third" "item")
echo "Number of items in original array: ${#array[*]}"
for ix in ${!array[*]}
do
printf " %s\n" "${array[$ix]}"
done
echo
arr=(${array[*]})
echo "After unquoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done
echo
arr=("${array[*]}")
echo "After * quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done
echo
arr=("${array[@]}")
echo "After @ quoted expansion: ${#arr[*]}"
for ix in ${!arr[*]}
do
printf " %s\n" "${arr[$ix]}"
done
</pre>
<pre class="screen">
array=({23..32} {49,50} {81..92})
echo "Array size: ${#array[*]}"
echo "Array items:"
for item in ${array[*]}
do
printf " %s\n" $item
done
</pre>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931706912"></a>1.3.11.1. 拆分字符串并转换为数组</h4></div><div><h5 class="subtitle">Split string into an array in Bash</h5></div></div></div>
<p>字符串</p>
<pre class="screen">
QUEUES="example|sss"
</pre>
<p>类似列表的数据结构</p>
<pre class="screen">
for caption in $(echo $QUEUES | tr '|' ' '); do
echo $caption
done
</pre>
<p>拆分为数组形式</p>
<pre class="screen">
captions=($(echo $QUEUES | tr '|' ' '))
for element in "${captions[@]}"
do
echo "$element"
done
for key in ${!captions[@]}; do
echo ${key} ${captions[${key}]}
done
</pre>
</div>
<div class="section"><div class="titlepage"><div><div><h4 class="title"><a id="idm45249931702864"></a>1.3.11.2. 数组转为字符串</h4></div></div></div>
<pre class="screen">
ids=(1 2 3 4);echo ${ids[*]// /|}
ids=(1 2 3 4); lst=$( IFS='|'; echo "${ids[*]}" ); echo $lst
array=(1 2 3 4); echo ${array[*]// /|}
array=(1 2 3 4);string="${ids[@]}";echo ${string// /|}
array=(1 2 3 4);string="${ids[@]}";echo ${string// /,}
IFS='|';echo "${[*]// /|}";
</pre>
</div>
</div>
<div class="section"><div class="titlepage"><div><div><h3 class="title"><a id="eval"></a>1.3.12. eval</h3></div></div></div>
<pre class="screen">
$ i=5
$ a_5=250
$ eval echo $"a_$i"
</pre>
<pre class="screen">
# neo="Neo Chen"
# name=neo
# eval "echo \$$name"
Neo Chen
</pre>
</div>
</div><div xmlns="" id="disqus_thread"></div><script xmlns="" type="text/javascript">
/* * * CONFIGURATION VARIABLES: EDIT BEFORE PASTING INTO YOUR WEBPAGE * * */
//if(document.domain == 'netkiller.github.io'){
var disqus_shortname = 'netkiller'; // required: replace example with your forum shortname
//}else{
//var disqus_shortname = 'neochan';
//}
/* * * DON'T EDIT BELOW THIS LINE * * */
(function() {
var dsq = document.createElement('script'); dsq.type = 'text/javascript'; dsq.async = true;
dsq.src = 'http://' + disqus_shortname + '.disqus.com/embed.js';
(document.getElementsByTagName('head')[0] || document.getElementsByTagName('body')[0]).appendChild(dsq);
})();
</script><noscript xmlns="">Please enable JavaScript to view the <a href="http://disqus.com/?ref_noscript">comments powered by Disqus.</a></noscript><a xmlns="" href="http://disqus.com" class="dsq-brlink">comments powered by <span class="logo-disqus">Disqus</span></a><br xmlns="" /><script xmlns="" type="text/javascript" id="clustrmaps" src="//cdn.clustrmaps.com/map_v2.js?u=r5HG&d=9mi5r_kkDC8uxG8HuY3p4-2qgeeVypAK9vMD-2P6BYM"></script><div class="navfooter"><hr /><table width="100%" summary="Navigation footer"><tr><td width="40%" align="left"><a accesskey="p" href="introduction.html">上一页</a> </td><td width="20%" align="center"><a accesskey="u" href="index.html">上一级</a></td><td width="40%" align="right"> <a accesskey="n" href="conditions.html">下一页</a></td></tr><tr><td width="40%" align="left" valign="top">1.2. Introduction </td><td width="20%" align="center"><a accesskey="h" href="../index.html">起始页</a></td><td width="40%" align="right" valign="top"> 1.4. conditions if and case</td></tr></table></div><script xmlns="">
(function(i,s,o,g,r,a,m){i['GoogleAnalyticsObject']=r;i[r]=i[r]||function(){
(i[r].q=i[r].q||[]).push(arguments)},i[r].l=1*new Date();a=s.createElement(o),
m=s.getElementsByTagName(o)[0];a.async=1;a.src=g;m.parentNode.insertBefore(a,m)
})(window,document,'script','//www.google-analytics.com/analytics.js','ga');
ga('create', 'UA-11694057-1', 'auto');
ga('send', 'pageview');
</script><script xmlns="" type="text/javascript">
var _bdhmProtocol = (("https:" == document.location.protocol) ? " https://" : " http://");
document.write(unescape("%3Cscript src='" + _bdhmProtocol + "hm.baidu.com/h.js%3F997cd4a7320a82d72cb74d179118f697' type='text/javascript'%3E%3C/script%3E"));
</script><script xmlns="" type="text/javascript" src="/js/q.js"></script></body></html>