zoukankan      html  css  js  c++  java
  • 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=57
    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 90 ];then
      echo 'excellent'
    elif [ $score -ge 70 -a $score -lt 90 ];then
      echo 'good'
    elif [ $score -ge 60 -a $score -lt 70];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 =1;i<=9;i++))
    do
       for ((j=1;j<=i;j++))
       do
         echo -n "$i*$j=$[$i*$j] "
       done
    echo
    done
    九九乘法表
    #!/bin/bash
    usr='mona'
    passwd='123'
    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
    登录用户操作
  • 相关阅读:
    Spring 事务不回滚
    Druid详细配置信息
    Servlet和JSP规范及版本对应关系
    CDN(内容分发网络)技术原理
    开发者需要了解的WebKit
    浏览器的渲染原理简介
    在浏览器中输入Google.com并且按下回车之后发生了什么?
    为什么说DOM操作很慢
    亿级Web系统搭建——单机到分布式集群
    linux下用rinetd做端口转发
  • 原文地址:https://www.cnblogs.com/mona524/p/6945425.html
Copyright © 2011-2022 走看看