Linux Shell学习简单小结(更新中……)

if-fi

Result:

(没有readme文件)

[work shell]$ sh if_e.sh
add readme ...
[workshell]$ sh if_e.sh
del readme ...
add readme ...

===================================================

if-else-fi

 

Result:

[work shell]$ sh if.sh
press y hello
y
hello
[work shell]$ sh if.sh
press y hello
n
bye..

===================================================

if-elif-else-if(函数传参1)

Result:

yanggang@barry$ ./param.sh 
0
1
2

3

===================================================

if-elif-else-if(函数传参2)

Result:

yanggang@barry$ ./param.sh 

0
1
2

3

===================================================

awk 

  

Result: 

[work]$ sh cal_lines.sh
ls: *.h: No such file or directory
91 test_performance_server.cpp
178 test_performance_ubclient1.cpp
230 test_performance_ubclient2_common_async.cpp
204 test_performance_ubclient2_common_block.cpp
206 test_performance_ubclient2_common_nonblock.cpp
191 test_performance_ubclient2_common_single_block.cpp
193 test_performance_ubclient2_common_single_nonblock.cpp
237 test_performance_ubclient2_nshead_async.cpp
220 test_performance_ubclient2_nshead_block.cpp
218 test_performance_ubclient2_nshead_nonblock.cpp
192 test_performance_ubclient2_nshead_single_block.cpp
192 test_performance_ubclient2_nshead_single_nonblock.cpp
2352 

 

===================================================

 linux实现两个文件内容相加(3种解法)

 

 a.txt(10行)     b.txt(9行)

 

  a.txt                  b.txt

 

解法一

  

运行结果:

[work]$ sh cal_ab1.sh
1 83
1 77
0 128
24 195
1 130
68 227
5 132
197 233
9 146

--------------------------------------------------------------------------------------

解法二

运行结果:

[work]$ sh cal_ab2.sh
1 83
1 77
0 128
24 195
1 130
68 227
5 132
197 233
9 146
0 8

 

--------------------------------------------------------------------------------------

解法三

运行结果:

[work]$ sh cal_ab3.sh
1       83
1       77
0       128
24      195
1       130
68      227
5       132
197     233
9       146
0       8 

 

--------------------------------------------------------------------------------------

评析:

解法一,结果不准确,只输出了前9行

解法二,结果正确,但不够简洁

解法三,结果正确,简洁

===================================================

 while循环


运行结果:

yanggang@barry$ ./tmp.sh 
0
24
48
72
96
120
144
168
192
216
240
264
288
312
336
360
384
408
432
456
480
504
528
552
576
600
624
648
672
696
720
744
768
792

 

  

 -------------------------------------------------------------------------------

参考拓展:

Linux Make(Makefile)由浅入深的学习与示例剖析

shell if语句 示例:文件或目录是否存在或有执行权限

linux实现两个文件内容相加

awk中NR与FNR

百度面试及总结4 

shell基础知识

关于RANDOM 的例子

 shell函数(传参)的使用

 

===================================================

posted @ 2011-01-06 15:08  SpringMVC+Hibernate  阅读(136)  评论(0编辑  收藏  举报
友情链接:厦门事业单位