zoukankan      html  css  js  c++  java
  • 11-day11-if-for-while

    11-day11-if-for-while

    1. export age //声明全局变量

    2. $ ${} $[]

      [root@bogon ~]# echo $age
      100
      [root@bogon ~]# echo ${age}
      100
      [root@bogon ~]# echo $[age]  //$[]是可以计算
      100  
      [root@bogon ~]# echo $[10%3]
      1
      [root@bogon ~]# echo $[10/3]
      3
      
    3. (( ))

      [root@bogon ~]# age=100
      [root@bogon ~]# ((age >10))
      [root@bogon ~]# echo $?
      0
      
    4. 关系运算符 与(())连用

      <
      >
      <=  
      >=  
      ==
      !=
      &&
      ||
      
      //*****// c+ 与 ((c+))
      [root@bogon ~]# c=2
      [root@bogon ~]# c+=2
      [root@bogon ~]# echo $c
      22
      [root@bogon ~]# b=3
      [root@bogon ~]# ((b+=3))
      [root@bogon ~]# echo $b
      6
      
    5. test命令 [] 可以达到同样的效果

      [ $x -gt 1 ]
      [ $user = 'cx2c' -a $password='cx2c' ]   //a 是and
      [ $user = 'cx2c' -o $password='cx2c' ]   //o是or
      
      
      [root@localhost cx2c]# cat chech_file.sh 
      #!/bin/bash
      read -p "please input file " file
      if [ -b $file ];then
      echo "$file is a block"
      elif [ -f $file ];then
      echo "$file is a file"
      elif [ -d $file ];then
      echo "$file dict"
      else
      echo "unknow"
      fi
      
    6. shell里所有的计算器

      $[]
      (())
      $(())
      expr
      bc
      bc -l
      echo 'scale=2;1/3'|bc -l | cut -d'.' -f2
      
      [root@bogon ~]# expr 1+2
      1+2
      [root@bogon ~]# expr 1 + 2
      3
      
    7. 测试命令 test [] [[]] (())

      [root@bogon ~]# test -n ''
      [root@bogon ~]# echo $?
      1
      [root@bogon ~]# test -n 'ads'
      [root@bogon ~]# echo $? 
      0
      [root@bogon ~]# [ -n 'ads' ]
      [root@bogon ~]# echo $?
      0
      
    8. 判断

      -eq: 等
      -ne:不等
      -gt:大于
      -ge:大于等于
      -lt:小于
      -le:小于等于
      -b:块设备
      -d:文件夹
      -e:文件存在
      -f:文件存在
      
    9. VISUAL BLOCK 编辑模式

      ctrl+v  
      上下选择光标选择行  
      I进入insert 位置首行    
      写入#    
      两下esc  
      

    10. shell read

      read -p 'Please Input your username' username
      
    11. if while 判断文件类型

      #!/bin/bash
      read -p "please input file " file
      while :
      do
      if [ -z $file ];then
      read -p "please input file " file
          continue 
      else
          break
      fi
      done 
      if [ -b $file ];then
          echo "$file is a block"
      elif [ -f $file ];then
          echo "$file is a file"
      elif [ -d $file ];then
          echo "$file dict"
      else
          echo "unknow"
      fi                  
      
    12. while 循环

      while ((count <10))
      do
      ...
      done
      
    13. if 循环

      if [ -z $file];then
          ...
      elif[ !-z $file];then
          ...
      else 
          ...
      fi
      
    14. for循环

      WHILE :
      DO
      
      DONE
      
      FOR (( )) 
      DO
      
      DONE      
      
      双小括号 不用$ 
      
      while 标志位
      
    15. 输入账号密码授权执行命令-tag

    16. 输入账号密码授权执行命令

    17. if [] 判断

    18. 输入账号密码授权执行命令

    19. 打印乘法表

    20. 判断路径文件类型

    21. 创建30用户并且设置密码

  • 相关阅读:
    Java——class对象
    Java——HashSet和TreeSet的区别
    Java——普通数据类型转化为String
    Java——Iterator迭代器
    Java——ArrayList和LinkedList的区别(转)
    Java——警告消除
    Object类——toString
    Java——动态调用类中方法
    SharePoint使用jsom查询当前用户信息
    SharePoint列表模板(.stp)
  • 原文地址:https://www.cnblogs.com/cx2c/p/6946076.html
Copyright © 2011-2022 走看看