Shell 语句
一 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 语句的更多相关文章
- shell语句for循环
一:常用格式 格式一 for 变量 do 语句 done 格式二 for 变量 in 列表 do 语句 done 格式三 for ((变量=初始值; 条件判断; 变量变化)) do 语句 done 二 ...
- 简单的shell语句
1,重启tomcat 脚本: pid=`ps -ef|grep tomcat |grep -v grep |awk '{print $2}'` ##取tomcat的进程号,awk处理字符串 ,取一行的 ...
- 测试常用shell语句——数值,数组类型;函数创建
一.特殊类型的变量 shell下默认的变量类型为字符串类型 1,数值类型 如果进行数值运算,有这么几种方法 方法一: declare -i sum sum=+ echo $sum 方法二: sum=$ ...
- 轻便的一句话反弹shell语句
反弹shell往往是在攻击者无法直接连接受害者的情况下进行的操作,原因有很多,例如目标是局域网,或者开启防火墙的某些策略等情况,而这时,我们就可以让受害者主动向攻击者发起连接,被控端发起请求到控制端某 ...
- shell语句记录-awk
cat ./daily_uv/daily_uv_20140104 | awk '{fr[$1]+=$3; k=$1 "_" $2; av[k]+=$3;} END{for (k i ...
- MySQL常用shell语句
1.连接数据库 格式:mysql -h ip -P port -u user -p 2.修改某一列的值 格式:update tablename set column1 = 'xxx', column2 ...
- shell语句
一.判断目录是否存在:#!/bin/bash#/bin/bash -n filename.sh 判断语句是否正确 DIR=/root/zhjif [ ! -d $DIR ];then mkdir $D ...
- hbase各种遍历查询shell语句 包含过滤组合条件
import java.io.IOException; import java.util.ArrayList; import java.util.Arrays; import java.util.Li ...
- 常用的shell语句 【awk】去重,排列
目的:从日志access.log中,筛选出IP来,并统计每个IP出现的次数,然后显示出来. 因为:awk = 扒IP shot = 排序 uniq = 去重 所以:awk '{print $1} ...
随机推荐
- figure margins too large错误解决
使用Rstudio,遇到下面这个错误: figure margins too large 这是因为界面右下角的“plot”窗口太小,显示不了,将右下角的窗口调大就能解决
- x264命令行工具(x264.exe)源码整体分析
该命令行工具调用的是libx264,就是一个使用该库的示例程序 X264命令行工具的源代码在x264中的位置如下图所示(红框里面的). X264命令行工具的源代码的调用关系如下图所示. Additio ...
- php windows 扩展redis
一:客户端安装redis (1)下载地址:https://github.com/dmajkic/redis/downloads 根据电脑是多少位的使用对应的文件,如我的是64bit,那么我就选择64b ...
- linux oracle error解决记录
1.sqlplus / as sysdba后使用select instance_name,status from v$instance后出错: ERROR:ORA-01034: ORACLE not ...
- Linux之(node.js)服务
1.1下载源码 你需要在下载最新的Nodejs版本, https://nodejs.org/en/download/ http://nodejs.org/dist/ 现在以node-v7.7.1.ta ...
- Spring MVC的路径匹配
Spring MVC中的路径匹配比起标准web.xml的servlet映射要灵活得多.路径匹配的默认策略是由org.springframework.util.AntPathMatcher实现的.顾名思 ...
- 使用MyBatis_Generator工具jar包自动化生成Dto、Dao、Mapping 文件
由于MyBatis属于一种半自动的ORM框架,所以主要的工作将是书写Mapping映射文件,但是由于手写映射文件很容易出错,所以查资料发现有现成的工具可以自动生成底层模型类.Dao接口类甚至Mappi ...
- [python数据结构] hashable, list, tuple, set, frozenset
学习 cs212 unit4 时遇到了 tuple, list, set 同时使用的问题,并且进行了拼接.合并操作.于是我就被弄混了.所以在这里进行一下总结. hashable and unhasha ...
- 移动端之touch事件--手指的滑动事件
转自[B5教程网]:http://www.bcty365.com/content-142-5243-1.html 总结:touchmove的最后坐标减去touchstart的起始坐标.X的结果如果正数 ...
- 段合并 segments merge 被删除的文档的删除时间
2.5 段合并 每个索引分为多个“写一次,读多次”的段 write once and read many times segments 建立索引时,一个段写入磁盘以后就不能更新:被删除的文档的信息存 ...