一 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. 使用 JDB 调试器

    您可以使用调试 applet 或应用程序的 jdb 命令来调试 Servlet. 为了调试一个 Servlet,我们可以调试 sun.servlet.http.HttpServer,然后把它看成是 H ...

  2. 支付宝热补丁技术— AndFix原理[阿里Hao]

    本文由嵌入式企鹅圈原创团队成员.阿里资深project师Hao分享. 上次我们介绍了用dexposed方案实施热补丁的原理.它本质上就是hook要改动的函数.这样一来在正式版本号公布时就不能直接拿热补 ...

  3. day20常用模块

    一.正则内容的补充 import re # ret = re.findall(r'www\.baidu\.com|www\.oldboy\.com','www.baidu.com') # # ret ...

  4. 2、easyUI-创建 CRUD可编辑dataGrid(表格)

    在介绍这节之前,我们先看一下效果图: 双击可以进入编辑

  5. 48、ViewFlow ---- 滑动广告页

    <!-- main.xml --> <?xml version="1.0" encoding="utf-8"?> <LinearL ...

  6. [Sdoi2011]火星移民

    2283: [Sdoi2011]火星移民 Time Limit: 40 Sec  Memory Limit: 512 MBSubmit: 119  Solved: 56[Submit][Status] ...

  7. [置顶] 我的Android进阶之旅------>Android解决异常: startRecording() called on an uninitialized AudioRecord.

    今天使用AudioRecord进行录音操作时候,报了下面的异常. E/AndroidRuntime(22775): java.lang.IllegalStateException: startReco ...

  8. document write & close

    在载入页面后,浏览器输出流自动关闭.在此之后,任何一个对当前页面进行操作的document.write()方法将打开—个新的输出流,它将清除当前页面内容. 必须确保调用document.close() ...

  9. Python 获取文件路径及文件目录

    import os print (os.path.dirname(__file__)) print (os.path.abspath(__file__)) print (os.path.abspath ...

  10. boost之时间timer

    C++一直缺乏对时间和日期的处理能力,一般借助于C的struct tm和time():timer包含三个类其中timer,progress_timer是计时器类,进度指示类是progress_disp ...