shell高亮示例

2021-10-20 21:18:41 字數 2746 閱讀 9188

#!/bin/bash

# define log & color

readonly fg_grey=

"30"

#灰色readonly fg_red=

"31"

readonly fg_green=

"32"

readonly fg_yellow=

"33"

readonly fg_blue=

"34"

#前景色藍色

readonly fg_violet=

"35"

#紫色readonly fg_sky_blue=

"36"

readonly fg_white=

"37"

readonly bg_red=

"41"

readonly bg_green=

"42"

readonly bg_yellow=

"43"

readonly bg_blue=

"44"

readonly bg_violet=

"45"

readonly bg_skyblue=

"46"

readonly bg_white=

"47"

readonly log_debug=

"[除錯]"

readonly log_info=

"[資訊]"

readonly log_warn=

"[警告]"

readonly log_error=

"[錯誤]"

function debug(

)m$\033[0m $1"

}function info(

)m$\033[0m $1"

}function warn(

)m$\033[0m $1"

}function error(

)m$\033[0m $1"

}function coloredlog(

)function choosecontext(

)# do

# echo "$"

# done

echo -n "choose one: "

read inputcontext

if["tx"=$

];then

inputcontext=

"context-tx"

fiif

["pre"=$

];then

inputcontext=

"context-pre"

fiif

["dc1"=$

];then

inputcontext=

"context-dc1"

fiif

["prd"=$

];then

inputcontext=

"context-prd"

fi choosecontextresult=

$(kubectl config use-context $

) info "$"

}function chooseresource(

) -n $

}function intodocker(

)..."

echo -n "input container name: "

read containername

pods=

($(kubectl get pod -n $

|grep $

|awk'')

) info "正在查詢pod列表..."

num=0

for pod in$do

echo

"$: $"

let num++

done

echo -n "choose a pod: "

read podnum

info "正在執行命令:kubectl exec -it -n $

$ --container $ /bin/bash"

kubectl exec -it -n $

$ --container $ /bin/bash

}# config env

info "正在設定環境變數..."

source ~/.bash_profile

info "正在查詢集群..."

choosecontext

#info "正在收集資源..."

#chooseresource

intodocker

#kubectl config use-context context-pre

##podname=$(kubectl get pod -n edu |grep edu-dating |awk '')

##echo "edu-dating podname:$"

##kubectl exec -it -n edu $ --container edu-dating /bin/bash

##globalcontext=default

# print context

log=

"this is a log string"

bold=

"01"

#加粗underline=

"04"

#下劃線

blink=

"05"

#閃爍

shell指令碼示例

shell基礎 一 迴圈1 100,並計算1 2 3 4 5 6 7 8 9 10的和 bin bash sum 0 for i 1 i 100 i dowhile i le 10 dosum sum i break done done echo sum me 注意幾點 1.sum 0要進行變數的初...

shell程式設計示例

is root.sh bin bash 通過環境變數判斷 test env grep user cut d f 2 if test root then echo current user is root.else echo not root.fi注意 給指令碼賦予執行許可權,如 chmod 755 ...

shell的典型應用 shell的高亮顯示

基本格式 echo e 終端顏色 顯示的內容 結束後的顏色 例項 1 echo e e 1 66m i am handsome e 1 0m 其中 e 1 66m中的1表示設定終端顏色,如果為0則不設定終端顏色 2 echo e e 1 66m i am handsome tput sgr0 tpu...