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)
# !/bin/sh
type=1 # 1, 2, 3(a,abc,123)
function getVal(){
echo "$1"
}
if [ "$type" == "1" ]; then
for((i=0;i<4;i++))
do
eval getVal $i
done
elif [ "$type" == "2" ]; then
echo "type"
else
echo "none"
fi
Result:yanggang@barry$
./param.sh0
1
2
3
===================================================
if-elif-else-if(函数传参2)
# !/bin/sh
#type=1 # 1, 2, 3(a,abc,123)
function getVal(){
echo "$1"
}
function inputVal(){
if [ "$1" == "1" ]; then
for((i=0;i<4;i++))
do
eval getVal $i
done
elif [ "$1" == "2" ]; then
echo "type"
else
echo "none"
fi
}
inputVal 1 # 1 is a param
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循环
# !/bin/sh
TOP_NUM=800
index=0
function url_down(){
while [ $index -le $TOP_NUM ]
do
echo $index
index=`expr $index + 24`
done
}
url_down
运行结果:
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函数(传参)的使用
参考推荐:
Linux Shell函数返回值
Linux 之 shell 比较运算符(推荐)
Linux Shell学习简单小结(推荐)
SHELL学习笔记----IF条件判断,判断条件
分享到:
相关推荐
linux shell学习资料:Linux Shell从入门到精通、Linux Shell编程艺术、Linux Shell脚本攻略
Linux_shell脚本全面学习 Linux_shell脚本全面学习
资源名称:Linux Shell脚本学习基础视频资源目录:【】11a00d99b60c4e2eba3440b8aa3a6bdd【】linux_shell脚本编程_01认识shell,如何编写shell脚本和执行【】linux_shell脚本编程_02vivim简单的常用操作【】linux_...
Linux-shell脚本全面学习.pdf
shell学习基本命令,可以帮助初学者快速掌握较全面的shell脚本知识
Linux shell是学习Linux必须掌握的脚本之一,该文档为本人学习Shell脚本时总结的一些基础知识,包括Shell的语法、简单示例和总结,欢迎下载学习。
Linuxshell大作业.pdf
LINUX SHELL命令练习 题
linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux shell编程指南linux ...
linux shell 视频教学 轻松学习shell
shell是用户和Linux操作系统之间的接口。 什么是shell Linux系统的shell作为操作系统的外壳,为用户提供使用操作系统的接口。它是命令语言、命令解释程序及程序设计语言的统称。 shell是用户和Linux内核之间的...
linux shell 应用.chm,学习linux shell资料
linuxShell脚本编写实验7报告.pdf
本书旨在通过理清Linux Shell编程的脉络,从基本概念着手,以丰富、实用的范例作为辅助,使读者能够深入浅出的学习LinuxShell编程。 本书的每一章节都配有综合案例,这些综合案例不仅可以使读者复习前面所学的...
Linux Shell Scripting Cookbook(3rd) 英文mobi 第3版 本资源转载自网络,如有侵权,请联系上传者或csdn删除 查看此书详细信息请在美国亚马逊官网搜索此书
这是学习Shell的简单例子这是学习Shell的简单例子这是学习Shell的简单例子
分别有以下这些内容的资料 Linux与unix shell编程指南 Bash参考手册 Expect中文教程 Expect简介和应用 Expect命令基本语法 高级Bash脚本编程指南 高级Shell脚本编程 Shell命令合集
linux shell 编程电子书,学习linux shell很不错的资料,高清的
LinuxShell脚本编程实例.pdf
Linux Shell脚本手册 - 第三版,. This book will take you through useful real-world recipes designed to make your daily life easier when working with the shell.