Shell if

if

Shell 中的 if 语句的使用语法如下:

if[条件] then 指令 fi

或者:

if[条件];then 指令 fi

分号相当于命令换行,上面两种语法等同。

elif

elif 的语法如下:

if[条件] then 指令 elif 条件 then 指令 else 指令 fi

Shell case

Shell 中的 case 语句的语法如下:

case "字符串变量" in 值1) 指令1 ;; 值2) 指令2 ;; *) 指令 esac

变量加颜色

RED_COLOR='\E[1;31m' GREEN_COLOR='\E[1;32m' YELLOW_COLOR='\E[1;33m' BLUE_COLOR='\E[1;34m' PINK='\E[1;35m' RES='\E[0m' echo -e "${RED_COLOR}===============red color=======${RES}" echo -e "${YELLOW_COLOR}===============yellow color=======${RES}"