1.条件判断式

按照文件类型进行判断:

两种判断格式:

test -e /root/install.log

[ -e /root/install.log ]

判断命令是否正确执行:

[ -d /root ] && echo "yes" || echo "no"

按文件权限判断:

两个文件之间的比较:

[ /root/stu.txt -ef /tmp/stu.txt]

两个整数之间的比较:

字符串的判断:

a=21,b=56

[ "$a" == "$b" ]

多重条件的判断:

2.流程控制

单分支语句if:

判断登陆用户是否为root:

vim isRoot.sh

#!/bin/bash

test=$(env | grep USER |cut -d "=" -f 2)

if [ "$test" == "root"];then

  echo "the user is root"

fi

双分支if语句:

read -t 30 -p "please enter a dir: "dir

if [ -d "$dir" ]

  then

    echo "is dir"

  else

    echo "no"

fi

判断Apache是否启动

test=$(ps aux | grep httpd |grep -v grep)

if [ -n "$test" ]

  then

    echo "$(date) httpd is running"

  else

    echo "httpd is not running"

    services httpd start

fi

多分支if语句:

多分支case语句:

for循环:

cd /root/test/

ls *.tar.gz > ls.log

ls *.tgz >> ls.log

for i in $( cat ls.log )

  do

    tar -zxf  $i & > /dev/null

  done

rm -rf ls.log

for i in $(cat /etc/passwd | grep /bin/bash |grep -v root |cut -d ":" -f1)

  do

    userdel -r $i

  done

while循环和until循环:

最新文章

  1. Python Day21
  2. Linux如何找出用户的创建时间
  3. php5.5安装及phpmyadmin&nginx配置php模块
  4. DelegatingFilterProxy
  5. NSMutableArray 根据key排序
  6. Inaccurate values for “Currently allocated space” and “Available free space” in the Shrink File dialog for TEMPDB only
  7. MSP430常见问题之IO端口类
  8. Ubuntu 14.04 SSH + 远程登录xrdp
  9. HDU 5920 Ugly Problem 【模拟】 (2016中国大学生程序设计竞赛(长春))
  10. django 模板视图,表单视图,各种视图
  11. Spring security oauth2最简单入门环境搭建
  12. Python -- Web -- WSGI
  13. 解决phpcms V9缩略图模糊的方法
  14. 理解Go Interface
  15. html基础和CSS选择器
  16. [C++ Primer Plus] 第10章、对象和类(一)程序清单——辨析三个const
  17. 【问题解决方案】之 关于某江加密视频swf专用播放器仍无法播放的问题
  18. python-异常处理、元类
  19. vCenter简单查看多少虚拟机在开机状态和一共多少虚拟机
  20. Oracle EBS - Setup: 配置文件Profile

热门文章

  1. 构建Ruby开发环境(Windows+Eclipse+Aptana Plugin)
  2. 中间件 WSGI
  3. C++友元概念
  4. java 图片Base64字符串转图片二进制数组
  5. yii框架模型操作
  6. 获取电脑连接WiFi的信息
  7. C#无边框窗体移动的三种方法
  8. Linux Shell基础 Bash常见命令 history、alias命令以及常用快捷键
  9. 机器学习算法之:KNN
  10. 【HackerRank】Cut the tree