linux 几个简单shell脚本demo
来源:互联网 发布:搜索引擎优化实战培训 编辑:程序博客网 时间:2024/05/29 13:18
linux 几个简单shell脚本demo
#!/bin/bashtest=$(env | grep USER | cut -d "=" -f 2) if [ "$test"==root ] then echo "current user is root"fi # 当前用户是
#!/bin/bashread -t 30 -p "please input a dir:" dirif [ -d "$dir" ] then echo "is dir" else echo "no no dir"fi#输入的 是否目录
#!/bin/bashtest=$(df -h | grep sda1 | awk '{print $5}' | cut -d "%" -f 1)echo "$test"if [ "$test" -ge "2" ];then echo "disk sda1 gt 2"fi#diskwarn 硬盘大小警告
#!/bin/bashtest=$(ps aux | grep httpd | grep -v grep)if [ -n "$test" ] then echo "httpd is ok" else echo "httpd in not start" /etc/rc.d/init.d/httpd startfi# 重启apace服务
#!/bin/bash#字符界面加减乘除计算器read -t 30 -p "please input num1: " num1read -t 30 -p "please input num2: " num2#通过read命令接收要计算的数值,并赋予变量read -t 30 -p "please input a operator: " ope#接收符号if [ -n "$num1" -a -n "$num2" -a -n "$ope" ]#第一层判断, 变量中都有值 then test1=$(echo $num1 | sed 's/[0-9]//g') test2=$(echo $num2 | sed 's/[0-9]//g') #判断是否为数值 if [ -z "$test1" -a -z "$test2" ] #第二层判断,用来判断num1 num2 为数值 #如果变量test1 test2的值为空 则证明num1 num2是数字 then #如果test1和test2是数字 则执行以下命令 if [ "$ope" == '+' ] #第三层判断用来确认运算符 then sum=$(( $num1 + $num2 )) elif [ "$ope" == '-' ] then sum=$(( $num1 - $num2 )) elif [ "$ope" == '*' ] then sum=$(( $num1 * $num2 )) elif [ "$ope" == '/' ] then sum=$(( $num1 / $num2 )) else echo "please enter a vaild symobl" exit 10 #输入无效的运算符 fi else #如果test1 test2不为空,说明num1和num2不是数值 echo "please enter a vald value" #提示输入有效的数值 exit 11 fifiecho " $num1 $ope $num2 = $sum "#输出数值运算的结果
0 0
- linux 几个简单shell脚本demo
- 几个简单shell Demo
- linux shell几个小demo
- 几个简单的shell脚本
- shell初学---几个简单的shell脚本
- linux系统-shell编程-几个shell脚本
- 几个 简单的shell 脚本 借鉴一下
- 简单的几个shell脚本一
- 简单的几个shell脚本二
- 简单的几个shell脚本三
- 简单的几个shell脚本四
- 简单的几个shell脚本五
- 简单的几个shell脚本六
- 简单的几个shell脚本七
- 简单的几个shell脚本八
- linux shell脚本简单示例
- Linux简单的shell脚本
- Shell脚本Demo
- Ubuntu 15.04 clang++ 3.6 编译boost 1.59/1.55
- 山峰
- 将矩阵顺时针旋转90度 leetCode:Rotate Image
- Convert Sorted List to Binary Search Tree
- Java中的进制转换,练习
- linux 几个简单shell脚本demo
- UIAlertView提示控件和UIActionSheet的使用
- CodeForces-327A Flipping Game
- ant 中 if else
- 你不知道的JavaScript--Item25 创建对象(类)的8种方法总结
- IOS9自定义UIWindow被键盘盖住(在键盘下面)解决方法
- javaWeb开发之基础--------------MySQL数据库总结
- uva548
- tyvj|P1089 smrtfun