Advertisement
Guest User

Untitled

a guest
Aug 22nd, 2019
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. envsubst字面上看是环境变量替换的意思,实际功能也如此。
  2.  
  3. envsubst从输入中读取文本并输出,如果遇到环境变量,会解析环境变量。
  4.  
  5. ```shell
  6. localhost:shell wangwei$ export hello=1
  7. localhost:shell wangwei$ envsubst
  8. hello$hello
  9. hello1
  10. ```
  11.  
  12.  
  13. 直接在shell中输入envsubst会读标准输入写入标准输出,因此输入hello$hello被解析成hello1。常用的方式是通过模板生成文件:
  14.  
  15. ```shell
  16. localhost:shell wangwei$ export x=2
  17. localhost:shell wangwei$ export y=5
  18. localhost:shell wangwei$ echo $x+$y > template.txt
  19. localhost:shell wangwei$ envsubst < template.txt > conf.txt
  20. ```
  21.  
  22. conf.txt中的内容:
  23.  
  24. ```shell
  25. 2+5
  26. ```
  27.  
  28. 在编写Dockerfile的时候常常使用envsubst这个命令。
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement