Shell usual rules of grammar Notes

Today, with the shell to write a script, there are many intermediate processing basic rules of grammar use, because so unskilled recorded for reference
Shell usual precautions

  • 1. The value of the assignment with variables not to take spaces

    byteEcho="64 bytes from"
    testA=0
    testB=$testA
    echo $testB
  • 2. Digital accumulation using let

    total_Count=0
    let total_Count=$total_Count+1 
  • 3. create and add an array of elements, traversing usage

    testArray=()
    testArray+=("J")
    testArray+=("L")
    testArray+=("Lily")
    
    for name in ${testArray[@]}
    do 
    echo $name
    done
  • 4. The relationship between the string comprises, processing can use wildcards

    A="helloworld"
    B="low"
    if [[ $A == *$B* ]];
    then
      echo "包含"
    else
      echo "不包含"
    fi
  • Condition determination 5.if [] to leave a space inside the process variables (both sides must have spaces)

    if [ $ip = "Array" ] 
  • 6. determines whether there is a variable! To

    if [ ! $failArray ]
  • Color control output terminal 7.shell

    Output format control effect:
    \ 033 [0m turn off all attributes
    \ 033 [1M set high brightness
    \ 03 [4m underlined
    \ 033 [scintillation 5m
    \ 033 [7M reverse display
    \ 033 [8M blanking
    \ 033 [30m - \ 033 [ 37m set the foreground color
    \ 033 [40m - \ 033 [ 47m set the background color

    Format control the cursor position or the like:
    \ 033 [nA move the cursor on the line n
    \ 03 [nB cursor down n rows
    \ 033 [nC cursor right row n
    \ 033 [nD cursor left row n
    \ 033 [y; xH provided the cursor position
    \ 033 [2J clear screen
    \ 033 [K to clear the contents from the cursor to the end of
    \ 033 [s save cursor position
    \ 033 [u restore the cursor position
    \ 033 [? 25l hide the cursor

    \ 33 [? 25h display cursor

    Finishing:
    color coded / Action
      0 to reset the properties of the default settings
      1 provided Bold
      2 luminance half set (to simulate the color of a color display)
      4 set underscore (to simulate the color of a color display)
      5 provided scintillator
      7 is provided inverted image
      22 is provided Usually density
      24 is closed underline
      25 is closed scintillator
      27 turn the reverse image
      30 is provided a black foreground
      31 arranged red foreground
      32 arranged green foreground
      33 arranged brown foreground
      34 arranged blue foreground
      35 arranged purple foreground
      36 disposed cyan foreground
      37 is provided as a white foreground
      38 in the absence disposed on the foreground color underline Province
      39 closed underlines the default foreground color
      40 set black background
      41 set red background
      set green background 42 is
      43 is provided on a brown background
      44 is provided on a blue background
      45 disposed purple background
      46 is provided on a cyan background
      47 provided on white background
      49 to set the default black background
    Effects can be superimposed, it requires the use of ";" separated, for example: blinking underline + + + black and white background is \ 033 [5; 4; 47; 30m blinking underline + + + black and white background is \ 033 [0m

#!/bin/bash
#
#下面是字体输出颜色及终端格式控制
#字体色范围:30-37
echo -e "\033[30m 黑色字 \033[0m"
echo -e "\033[31m 红色字 \033[0m"
echo -e "\033[32m 绿色字 \033[0m"
echo -e "\033[33m 黄色字 \033[0m"
echo -e "\033[34m 蓝色字 \033[0m"
echo -e "\033[35m 紫色字 \033[0m"
echo -e "\033[36m 天蓝字 \033[0m"
echo -e "\033[37m 白色字 \033[0m"
#字背景颜色范围:40-47
echo -e "\033[40;37m 黑底白字 \033[0m"
echo -e "\033[41;30m 红底黑字 \033[0m"
echo -e "\033[42;34m 绿底蓝字 \033[0m"
echo -e "\033[43;34m 黄底蓝字 \033[0m"
echo -e "\033[44;30m 蓝底黑字 \033[0m"
echo -e "\033[45;30m 紫底黑字 \033[0m"
echo -e "\033[46;30m 天蓝底黑字 \033[0m"
echo -e "\033[47;34m 白底蓝字 \033[0m"

#控制选项说明
#\033[0m 关闭所有属性
#\033[1m 设置高亮度
#\033[4m 下划线
echo -e "\033[4;31m 下划线红字 \033[0m"
#闪烁
echo -e "\033[5;34m 红字在闪烁 \033[0m"
#反影
echo -e "\033[8m 消隐 \033[0m "

#\033[30m-\033[37m 设置前景色
#\033[40m-\033[47m 设置背景色
#\033[nA光标上移n行
#\033[nB光标下移n行
echo -e "\033[4A 光标上移4行 \033[0m"
#\033[nC光标右移n行
#\033[nD光标左移n行
#\033[y;xH设置光标位置
#\033[2J清屏
#\033[K清除从光标到行尾的内容
echo -e "\033[K 清除光标到行尾的内容 \033[0m"
#\033[s 保存光标位置
#\033[u 恢复光标位置
#\033[?25| 隐藏光标
#\033[?25h 显示光标
echo -e "\033[?25l 隐藏光标 \033[0m"
echo -e "\033[?25h 显示光标 \033[0m"

Guess you like

Origin www.cnblogs.com/xiaoqiangink/p/12503792.html