摘要: #!/bin/bash#提示用户输入echo -n "Please enter number"read n #读入输入的值放到变量n中sd=0rev=""on=$n #将变量n的值保存到变量on中,方便以后用到echo "You put number is $n"while [$n -gt 0]do... 阅读全文
posted @ 2014-07-10 11:05 liu_ty10 阅读(926) 评论(0) 推荐(0) 编辑
摘要: #!/bin/bashcounter=0#变量files遍历一遍当前文件夹for files in *do#判断files是否为文件,如果是,counter变量值加1,再赋值给自己。 if [-f"$files"] then counter=`expr $counter + 1` fido... 阅读全文
posted @ 2014-07-10 10:16 liu_ty10 阅读(196) 评论(0) 推荐(0) 编辑
摘要: #!/bin/basha=$1 #将第一个命令行参数传递给变量a,第二个命令行参数传递给bb=$2if [-z $a] || [-z $b] #判断a 和 b 是否为空,只要有一个为空就打印提示语句并退出。then echo "please enter 2 no" exit 1fiif [$a ... 阅读全文
posted @ 2014-07-10 09:34 liu_ty10 阅读(208) 评论(0) 推荐(0) 编辑
摘要: 作者:xwjbs来自:http://blog.csdn.net/xwjbs转载的时候请注明作者和出处。没有作者的允许,严禁用于商业利益。托google、百度们成功的福,搜索引擎火了半边天。很多人都想跨到这个行业里边来。前两天在公司里边面试了一些人,基本上没有感到满意。不是说从业经验不够,有些也已经工... 阅读全文
posted @ 2014-07-10 08:29 liu_ty10 阅读(4769) 评论(1) 推荐(0) 编辑
摘要: BASH中的case结构,可以用于进行多项分支。case "$var" incondition1) ;;condition2) ;;*) default statments;;esac例如:#!/bin/bashecho "Hit a key, then hit return"read... 阅读全文
posted @ 2014-07-09 18:56 liu_ty10 阅读(184) 评论(0) 推荐(0) 编辑
摘要: 一、for循环for var in [ list ]do #code blockdone$var是循环控制变量,[list]是var需要遍历的一个集合,do/done对包含了循环体。如果do和for被写在同一行,必须在do前面加上“;”,如:for $var in [list]; do例如:#!/... 阅读全文
posted @ 2014-07-09 18:31 liu_ty10 阅读(203) 评论(0) 推荐(0) 编辑
摘要: 一、条件语句1、if [expression]then #code blockfi2、if [expression]then #code blockelse #code blockfi3、if [expression]then #code blockelse if [expression... 阅读全文
posted @ 2014-07-09 18:08 liu_ty10 阅读(242) 评论(0) 推荐(0) 编辑
摘要: #!/bin/bashhello="var1"echo $hellofunction func1 #定义函数func1{ local hello="var2" #定义内部变量hello echo $hello}func1 #进行函数调用echo $hello执行结果:总结:局部变量仅在函数内部起作用... 阅读全文
posted @ 2014-07-09 16:40 liu_ty10 阅读(2515) 评论(0) 推荐(0) 编辑
摘要: 一、一般变量#/bin/shnum=2echo "this is the ${num}nd" #shell脚本语言的变量如果紧连字母时,需要加上“{}”进行区分。输出结果:二、系统变量$#:传入脚本的命令行参数个数$*:所有命令行参数值,在各个参数值之间留有空格$0:命令本身(shell文件名)$1... 阅读全文
posted @ 2014-07-09 16:08 liu_ty10 阅读(188) 评论(0) 推荐(0) 编辑
摘要: #!/bin/sh #指定该脚本文件的解析程序,“#”用作注释,相当于C语言的"//"a="hello world!" #变量赋值。shell脚本中的变量无需定义,也没有类型。echo "A is:" #打印aecho $a程序执行结果: 阅读全文
posted @ 2014-07-09 15:51 liu_ty10 阅读(523) 评论(0) 推荐(0) 编辑