zoukankan      html  css  js  c++  java
  • 四、shell基础

    • shell脚本为文本文件

    • 文件通常以.sh结尾

    • 第一行:指定用哪个程序编译执行
      * # ! /bin/bash
      * # ! /bin/sh

    • 注释:#

    • 变量名:以字母或下划线开头,大小写敏感

    • 变量
      * 本地变量
      * 环境变量(全局变量)
      * 大写
      * export LANG
      * 赋值
      * 等号两边不能有空格
      * 给变量赋空值,在等号后加换行符
      * 显示变量的值:echo$var 或 echo ${var}
      * 清除变量:unset var
      * 显示所有的变量:set
      * 位置参量:
      * 从命令行接受参数
      * 脚本后每个用空格隔开的变量都为字符参量
      * 参量中有空格需加引号
      * (x表示第x个参数 * 当x大于9,要写成){x}

    • 任何命令进行时都将返回一个退出状态

    • 查看命令:echo %?

    • shell脚本返回最后一个命令的返回码

    • 返回码:exit N
      * 0,成功
      * 0,出错

    • 数组
      * 定义:arr=(v1,v2,…)
      * 引用
      * 引用变量:({arr[0]} * 数组个数:){#arr[]}
      * 所有元素:${arr[
      ]}
      * 赋值:arr[0]=hah

    • 时间
      * 显示
      * date +%Y/%m/%d
      * date +%H:%M
      * 今天:date +%Y/%m/%d
      * 昨天:date --date=‘1 days ago’ +%Y/%m/%d
      * 前天:date --date=‘2 days ago’ + +%Y/%m/%d

    • 判断

    * 判断是否为空:[var]
    * if [表达式]; then 语句 elif 语句 else 语句 fi
    * for var in 1 2 3 4 5 do 语句 done
    * for ((i=0;i<${num};i=i+1)) do 语句 done
    * while [condition] do 语句 done
    * until [condition] do 语句 done
    
    • 从文件或命令中逐行读取
      • cat file | while read line do echo $line done
      • car ls ./*.txt | while read line do echo $line done
  • 相关阅读:
    Enables DNS lookups on client IP addresses 域名的分层结构
    移除 URL 中的 index.php
    Design and Architectural Goals
    The Model represents your data structures.
    If a cache file exists, it is sent directly to the browser, bypassing the normal system execution.
    UNION WHERE
    cookie less
    http 2
    UNION DISTINCT
    联合约束 CONCAT()
  • 原文地址:https://www.cnblogs.com/linyk/p/12845939.html
Copyright © 2011-2022 走看看