一、shell
菜鸟教程地址 http://www.runoob.com/linux/linux-shell.html
二、数组
遍历数组,打印1到数组长度的值
#!/bin/bash
tests=(a b c)
for index in `seq 1 ${#tests[@]}`
do
echo $index
done
for index in $(seq 1 ${#tests[@]})
do
echo $index
done
例2
#两个数组11对应索引相同的第一个为存放目录,第二个数据的值为文件
#!/usr/bin/env bash
source ../global.cfg
k8s_url=${k8s_api_server}
image_url=${repo_server:-192.168.14.171:5000}
#两个数组11对应索引相同的第一个为存放目录,第二个数据的值为文件
replace_var_yaml_dirs=(
alertmanager
grafana
kube-state-metrics
node-exporter
prometheus
prometheus-operator
)
replace_var_yaml_files=(
alertmanager.yaml
grafana-deployment.yaml
kube-state-metrics-deployment.yaml
node-exporter-daemonset.yaml
prometheus-k8s.yaml
prometheus-operator.yaml
)
# 复制yaml文件到指定目录并替换变量
replaceYamlVarFun(){
local index
for index in $(seq 0 $[${#replace_var_yaml_files[*]} -1])
do
# echo ${replace_var_yaml_dirs[index]} " " ${replace_var_yaml_files[index]}
cp -f manifests/deployment/${replace_var_yaml_files[index]} manifests/${replace_var_yaml_dirs[index]}/
sed -i "s/image_url/${image_url}/g" manifests/${replace_var_yaml_dirs[index]}/${replace_var_yaml_files[index]}
done
echo "replace yaml var complete ......"
}
replaceYamlVarFun