一 test 测试:

测试命令 test [ ] [[ ]] (( ))
打开man test 逐一介绍每个参数

浮点计算:echo 'scale=2;1/3'|bc -l
 

测试操作
命令执行后会返回到一个系统变量中 $?
如果$?值为0 表示命令执行成功 否则为失败

二流程控制: if   while   for

#!/bin/bash
read -p 'please input username:' usr
read -p 'please input passwd:' passwd if [ $usr = 'alex' -a $passwd = 'alex3714' ];then
echo 'login successful'
else
echo 'username or password is worng'
fi

用户测试

!/bin/bash
age=
while :
do read -p 'input oldboy age:' ag if [ $ag -eq $age ];then
echo "bingo"
break
elif [ $ag -gt $age ];then
echo "the age is older"
else
echo "the age is younger"
fi if [ -z $ag ];then
continue
fi done

猜年龄

#!/bin/bash
read -p 'please input your score:' score if [ $score -ge ];then
echo 'excellent'
elif [ $score -ge -a $score -lt ];then
echo 'good'
elif [ $score -ge -a $score -lt ];then
ehco 'not bad'
else
echo 'bad'
fi

成绩查询

#!/bin/bash
read -p 'input your file: ' file
if [ -p $file ];then
echo "$file is block file"
elif [ -f $file ];then
echo "$file is reuler file"
elif [ -d $file ];then
echo "$file is directory file"
else
echo "$file is unkown"
fi

测文件类型

#!/bin/bash
for ((i =;i<=;i++))
do
for ((j=;j<=i;j++))
do
echo -n "$i*$j=$[$i*$j] "
done
echo
done

九九乘法表

#!/bin/bash
usr='mona'
passwd=''
tag=true
while $tag
do
read -p 'please input your name: ' name
read -p 'please input your password: ' pd
if [ $name = $usr ] && [ $pd = $passwd ];then
echo 'login successful'
while $tag
do
read -p 'input your indirction: ' cmd
if [ $cmd = 'quit' ];then
tag=false
else
$cmd
fi
done
fi
done

登录用户操作

Shell 语句的更多相关文章

  1. shell语句for循环

    一:常用格式 格式一 for 变量 do 语句 done 格式二 for 变量 in 列表 do 语句 done 格式三 for ((变量=初始值; 条件判断; 变量变化)) do 语句 done 二 ...

  2. 简单的shell语句

    1,重启tomcat 脚本: pid=`ps -ef|grep tomcat |grep -v grep |awk '{print $2}'` ##取tomcat的进程号,awk处理字符串 ,取一行的 ...

  3. 测试常用shell语句——数值,数组类型;函数创建

    一.特殊类型的变量 shell下默认的变量类型为字符串类型 1,数值类型 如果进行数值运算,有这么几种方法 方法一: declare -i sum sum=+ echo $sum 方法二: sum=$ ...

  4. 轻便的一句话反弹shell语句

    反弹shell往往是在攻击者无法直接连接受害者的情况下进行的操作,原因有很多,例如目标是局域网,或者开启防火墙的某些策略等情况,而这时,我们就可以让受害者主动向攻击者发起连接,被控端发起请求到控制端某 ...

  5. shell语句记录-awk

    cat ./daily_uv/daily_uv_20140104 | awk '{fr[$1]+=$3; k=$1 "_" $2; av[k]+=$3;} END{for (k i ...

  6. MySQL常用shell语句

    1.连接数据库 格式:mysql -h ip -P port -u user -p 2.修改某一列的值 格式:update tablename set column1 = 'xxx', column2 ...

  7. shell语句

    一.判断目录是否存在:#!/bin/bash#/bin/bash -n filename.sh 判断语句是否正确 DIR=/root/zhjif [ ! -d $DIR ];then mkdir $D ...

  8. hbase各种遍历查询shell语句 包含过滤组合条件

    import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Li ...

  9. 常用的shell语句 【awk】去重,排列

    目的:从日志access.log中,筛选出IP来,并统计每个IP出现的次数,然后显示出来. 因为:awk = 扒IP  shot = 排序  uniq =  去重 所以:awk '{print $1} ...

随机推荐

  1. What is the difference between application server and web server?

    http://stackoverflow.com/questions/936197/what-is-the-difference-between-application-server-and-web- ...

  2. gradle配置flavors上传nexus服务器

    分拆代码的过程中需要把核心代码编译成一个库上传到内部maven服务器上,所以研究了一下上传私库的方法. 首先拆分的是工具类库,这个库和java的库类似,没有配置flavors,所以按照网上通用的方法引 ...

  3. 什么是Web Services?

    什么是Web Services? Web Services 是应用程序组件 Web Services 使用开放协议进行通信 Web Services 是独立的(self-contained)并可自我描 ...

  4. hdu 1815(二分+2-sat)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1815 题意:给出n个牛棚.两个特殊点S1,S2的坐标.S1.S2直连.牛棚只能连S1或S2,还有,某些 ...

  5. Java_cpu飙升排查

    1.现象 top 2.根据上图找到进程ID=28790 3.查找28790下线占用cpu高的线程ID -o THREAD,tid,time 4.根据上图发现线程ID=29161,换算成16进制 pri ...

  6. 在Visual Studio 2015的Cordova项目中使用Gulp

    之前一直是在vs 2013中使用Cordova来开发移动app(目前有iPad版/iPhone版/安卓版),准备到下一个milestone的时候升级到2015,这两天在尝试各种东西. 2015中的co ...

  7. 九度OJ 1357:疯狂地Jobdu序列 (数字特性)

    时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:715 解决:263 题目描述: 阳仔作为OJ的数据管理员,每一周的题目录入都让其很抓狂,因为题目不是他出的,他控制不了出题的速度--在等题目 ...

  8. 【python】-- Django ORM(进阶)

    Django ORM(进阶) 上一篇博文简述了Django ORM的单表操作,在本篇博文中主要简述Django ORM的连表操作. 一.一对多:models.ForeignKey() 应用场景:当一张 ...

  9. a标签里面包含img标签,出现a标签的高度高于img标签好几个px

    问题:a标签里面包含img标签,出现a标签的高度高于img标签好几个px 解决: a元素下有一个匿名文本,这个文本外有一个匿名行级盒子,它有的默认vertical-align是baseline的,而且 ...

  10. PHP查看目录下的所有文件

    [1].[代码] [PHP]代码 跳至 [1] ? 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 ...