Shebang |
#!/bin/bash |
if |
if [ condition ] then statement else if [] then statement else statement fi |
按空格分割 |
for word in string |
按行分割 |
while read branch |
函数 |
func() {} func para1 para2 返回值 echo "$var" return_value=$(func para1 para2) |
传参 |
接收用户输入参数 $1, $2, $@, $* $@, $*区别: "$@"多个字符串"xx""yy","$*"一个字符串"xxyy" |
数组 |
arr=() ${arr[0]} arr=(${arr[@]} $new_item) |
执行命令字符串 |
eval $cmd |
echo |
识别转义 echo -e "\n" 行内打印 echo -n 打印需要加引号"",避免echo命令特殊处理(如:*) echo "$var" |
匹配和正则 |
controller_pod_name=$(kubectl get pod -n ingress-nginx | grep -o ‘nginx-ingress-controller[a-z0-9-]*‘) 过滤 grep -v "" 不是精确过滤:子串也会过滤掉 |
原文:https://www.cnblogs.com/wenlin-gk/p/9712415.html