[TOC] ## 安装 一般系统都带有 `apt-get install gettext-base` ## 格式 `envsubst < 模版文件 > 输出文件` eg: `envsubst < test.txt > bak.txt` ## 使用 ### 简单demo ``` # export TEST="a string to test envsubst" # cat test.txt $TEST # envsubst < test.txt > bak.txt # cat bak.txt a string to test envsubst ``` ### 循环中使用 redis-cluster.tmpl ``` port ${PORT} protected-mode no cluster-enabled yes cluster-config-file nodes.conf cluster-node-timeout 5000 cluster-announce-ip 39.10X.XX.XX //自己服务器IP cluster-announce-port ${PORT} cluster-announce-bus-port 1${PORT} appendonly yes ``` 直接执行 ``` $ for port in `seq 7000 7005`; do \ mkdir -p ./${port}/conf \ && PORT=${port} envsubst < ./redis-cluster.tmpl > ./${port}/conf/redis.conf \ && mkdir -p ./${port}/data; \ done ``` 输出 ``` ├── 7000 │   ├── conf │   │   └── redis.conf │   └── data ├── 7001 │   ├── conf │   │   └── redis.conf │   └── data ├── 7002 │   ├── conf │   │   └── redis.conf │   └── data ├── 7003 │   ├── conf │   │   └── redis.conf │   └── data ├── 7004 │   ├── conf │   │   └── redis.conf │   └── data ├── 7005 │   ├── conf │   │   └── redis.conf │   └── data └── redis-cluster.tmpl ```