一 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. 离散数学及其应用(Discrete Mathematica With Application 7th)学习笔记 第一章

    目前本人只进行到了第五章的章末补充练习,应该是从4月6号开始学习的,又是英文版,而且基本就下班回家抽2个小时左右去学,所以进度较慢. 由于本质是数学,除了一些程序处理和大计算量的问题,基本上一本草稿本 ...

  2. 如何给Eclipse添加一个JDK或JRE

    第一:  第二:  第三:  第四: 

  3. Intent跳转系统的应用

    1.从google搜索内容    Intent intent = new Intent();    intent.setAction(Intent.ACTION_WEB_SEARCH);    int ...

  4. dll 在进程中怎么区分的

    平时一直没想过这个问题,今天在测试输入法注入的时候才发现windows下dll在进程中是以名字区分的,即使是完全一模一样的DLL. 具体详情,容我慢禀 :   需求是这样的,只能含有一个a.DLL,这 ...

  5. 12个十分实用的JavaScript小技巧

    12个非常实用的JavaScript小技巧 在这篇文章中将给大家分享12个有关于JavaScript的小技巧.这些小技巧可能在你的实际工作中或许能帮助你解决一些问题. 使用!!操作符转换布尔值 有时候 ...

  6. o.a.catalina.core.AprLifecycleListener : An incompatible version [1.2.7] of the APR based Apache Tomcat Native library is installed, while Tomcat requires version [1.2.14]

    1.错误信息提示: 2019-04-16 22:02:05.811 ERROR 18112 --- [           main] o.a.catalina.core.AprLifecycleLi ...

  7. Android Studio下通过Gradle配置实现资源文件的模块化

    当开发一个app模块个数很多的时候,资源文件就会特别多,布局也会多起来,这时所有的layout都放在同一个目录下,就会显得臃肿,而且不好找相应的布局. 最近看到相关资料,发现在Android Stud ...

  8. 宇视4G设备采用GB/T28181协议成功接入EasyGBS国标流媒体平台的设置流程

    经过了多天的调试对接,终于将宇视的布控球顺利接入到了EasyGBS的国标平台,特地写一下对接过程中遇到的问题,希望能帮助大家避开一些麻烦: 第一步:电脑连接无线网络IPCWIFI,密码12345678 ...

  9. UESTC 491 Tricks in Bits

    Tricks in Bits Time Limit: 1000MS   Memory Limit: 65535KB   64bit IO Format: %lld & %llu Submit  ...

  10. js引入方式的弹框方法2

    html代码: <!DOCTYPE html> <html lang="zh-CN"> <head> <meta http-equiv=& ...