if的使用
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:44 iftest1
[oracle@localhost iftest]$ ./iftest1
Enter your name :lubinsu
[oracle@localhost iftest]$ ./iftest1
Enter your name :
you didn't enter your name!
[oracle@localhost iftest]$ cat iftest1
#!/bin/sh
#if test1
echo -n "Enter your name :"
read NAME
if [ "${NAME}" = "" ] ; then
echo "you didn't enter your name!"
fi
[oracle@localhost iftest]$ ./iftest1
Enter your name :lubinsu
[oracle@localhost iftest]$ ./iftest1
Enter your name :
you didn't enter your name!
[oracle@localhost iftest]$
grep输出检查
[oracle@localhost iftest]$ ll
total 16
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:50 grepif
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:44 iftest1
[oracle@localhost iftest]$ cat grepif
#!/bin/sh
# grepif
if grep "if" iftest1 > /dev/null 2>&1
then
echo "if is in the file"
else
echo "if is not in the file"
fi
[oracle@localhost iftest]$ ./grepif
if is in the file
用变量测试grep输出
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:44 iftest1
#!/bin/sh
# grepif
if grep "if" iftest1 > /dev/null 2>&1
then
echo "if is in the file"
else
echo "if is not in the file"
fi
[oracle@localhost iftest]$ cat grepstr
#!/bin/sh
# grepif
echo -n "please enter a list of name:"
read list
if echo ${list} | grep "lubinsu" > /dev/null 2>&1
then
echo "lubinsu is in the list"
else
echo "lubinsu is not in the list"
fi
[oracle@localhost iftest]$ ./grepstr
please enter a list of name:lubinsu luzhou
lubinsu is in the list
[oracle@localhost iftest]$ ./grepstr
please enter a list of name:luzhou
lubinsu is not in the list
这里有必要提下一些特定的shell变量:
case的使用:
[oracle@localhost iftest]$ cat caseselect
#!/bin/sh
#case select
echo "please select a number betewwn 1..5:"
read number
case $number in
1) echo "you select 1"
;;
2) echo "you select 2"
;;
*) echo "you select greater than 2"
exit 1
;;
esac
[oracle@localhost iftest]$ ./caseselect
please select a number betewwn 1..5:
2
you select 2
[oracle@localhost iftest]$ ./caseselect
please select a number betewwn 1..5:
4
you select greater than 2
for的使用:
[oracle@localhost iftest]$ cat for_i
#!/bin/sh
#for
for i in 1 2 3 4 5
do
echo $i
done
[oracle@localhost iftest]$ ./for_i
1
2
3
4
5
循环遍历文件:
[oracle@localhost iftest]$ cat for_files
#!/bin/sh
#for files
counter=0
for files in *
do
counter=`expr $counter + 1`
echo ${files}
done
echo "There is $counter files in `pwd` we need to process"
[oracle@localhost iftest]$ ./for_files
caseselect
for_files
for_i
grepif
grepstr
iftest1
There is 6 files in /home/oracle/testDir/iftest we need to process
while读取文件:
[oracle@localhost iftest]$ cat while_file
#!/bin/sh
#while file
while read LINE
do
echo $LINE
done < $1
[oracle@localhost iftest]$ ./while_file ll.out
total 52
-rwxr--r-- 1 oracle oinstall 222 Mar 10 15:44 caseselect
-rwxr--r-- 1 oracle oinstall 162 Mar 10 16:16 for_files
-rwxr--r-- 1 oracle oinstall 56 Mar 10 16:05 for_i
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:50 grepif
-rwxr--r-- 1 oracle oinstall 199 Mar 10 14:17 grepstr
-rwxr--r-- 1 oracle oinstall 128 Mar 10 13:44 iftest1
-rw-r--r-- 1 oracle oinstall 0 Mar 10 16:27 ll.out
分享到:
相关推荐
linux shell 控制流结构
讲述了shell中流程控制语句if_for_while_case_util_break_continue的用发和实例
D-Lab的12小时R基础知识介绍。了解如何在RStudio中使用R创建变量数据框、进行可视化、使用控制流结构等.zip
今天小编就为大家分享一篇关于浅谈shell脚本中的控制流结构,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来看看吧
作为系统核心部分,规则库引擎从源程序中抽取控制流结构,进行符合控制反向(IOC)机制的元数据的动态匹配与标记。采用时序逻辑规约和标记后的控制流结构对程序建模,并结合NuSMV模型验证器实现验证。实现了原型系统...
原理:将源代码解析为AST,遍历AST生成结构化字符串,最后解析结构化字符串得到控制流图。 使用:python CFG.py src [-o dir] 工具扫描src文件所有函数并在dir目录下生成控制流图,缺省为当前工作目录。
二、控制流结构 之 if then else P68 三、控制流结构 之 case P69 四、控制流结构 之 for循环 P70 五、控制流结构 之 until循环 P71 六、控制流结构 之 while循环 P72 七、控制循环 之 break P73 八、控制循环 之 ...
提出一种过程模型中控制流反模式的定义和检测方法,抽取不同过程模型中的控制流结构并将其规约为语言无关的过程结构树,基于不同控制流反模式的CAPDL定义,在过程结构树上查找与之对应的控制流反模式。该方法既支持...
运算符与控制流:掌握Rust中的运算符(如算术运算符、比较运算符和逻辑运算符)以及控制流结构(如if-else语句、循环和匹配表达式)。 二、所有权与生命周期 所有权系统:了解Rust的所有权模型,包括变量的作用...
Swift是一种支持多编程范式和编译式的开源编程语言,由苹果公司于2014年在WWDC(苹果开发者大会)上发布...控制流:Swift提供了各种控制流结构,如if语句、switch语句、for循环和while循环等,用于控制程序的执行流程。
你尤其应该理解以下内容:所有的 C 操作符、控制流结构、变量和指针的申 明和使用、字符串处理函数、exit()函数的使用和 stdio.h 中关于文件输入输 出的一组函数等等。 你还应该理解标准输入设备、标准输出设备和标准...
第18章_控制流结构; 第19章_shell函数; 第20章_向脚本传递参数; 第21章_创建屏幕输出; 第22章_创建屏幕输入; 第23章_调试脚本; 第24章_shell嵌入命令; 第25章_深入讨论; 第26章_shell工具; 第27章_几个脚本...
针对软件代码混淆算法中的内联方法存在混淆结果单一性问题,提出了一种多态内联代码混淆算法。...实验结果表明,提出的算法在程序复杂度以及控制流结构的复杂度方面都得到了很大提高,验证了其对代码混淆强度的提升。
第1章文件安全与权限 第2章使用find和xargs ...第18章控制流结构 第19章shell 函数 第20章向脚本传递参数 第21章创建屏幕输出 第22章创建屏幕输入 第23章调试脚本 第24章shell嵌入命令 第25章深入讨论 第26章shell 工具
18. 控制流结构 19. SHELL 函数 20. 向脚本传递参数 21. 创建屏幕输出 22. 创建屏幕输入 23. 调试脚本 24. SHELL 嵌入命令 25. 深入讨论 26. SHELL 工具 27. 几个脚本例子 28. 运行级别脚本 29. CGI 脚本 30. 常用 ...
第18章控制流结构 第19章shell 函数 第20章向脚本传递参数 第21章创建屏幕输出 第22章创建屏幕输入 第23章调试脚本 第24章shell嵌入命令 第五部分高级shell编程技巧 第25章深入讨论 第26章shell 工具 第27章几个...
第18章 控制流结构 第19章 shell函数 第20章 向脚本传递参数 第21章 创建屏幕输出 第22章 创建屏幕输入 第23章 调试脚本 第24章 shell嵌入命令 第25章 深入讨论 第26章 shell 工具 第27章 几个脚本例子 ...
018控制流结构.pdf 019shell 函数.pdf 020向脚本传递参数.pdf 021创建屏幕输出.pdf 022创建屏幕输入.pdf 023调试脚本.pdf 024shell嵌入命令.pdf 025深入讨论.pdf 026shell 工具.pdf 027几个脚本例子.pdf ...
文档是通过使用XMind思维导图对C#的控制流和高级数据结构诸如数组,String字符串的创建和基本操作进行总结,简单了解C#的基本知识点,为开发C#程序伏笔。
18-控制流结构.pdf 19-shell 函数.pdf 20-向脚本传递参数.pdf 21-创建屏幕输出.pdf 22-创建屏幕输入.pdf 23-调试脚本.pdf ................. ................. 30-常用shell命令.pdf SHELL 视频教程