Files
tldr/pages.zh/common/envsubst.md

21 lines
694 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# envsubst
> 用它们在 shell 格式字符串中的值替换环境变量。
> 要被替换的变量应以 `${var}` 或 `$var` 格式表示。
> 更多信息:<https://www.gnu.org/software/gettext/manual/html_node/envsubst-Invocation.html>。
-`stdin` 中替换环境变量并输出到 `stdout`
`echo '{{$HOME}}' | envsubst`
- 在输入文件中替换环境变量并输出到 `stdout`
`envsubst < {{path/to/input_file}}`
- 在输入文件中替换环境变量并输出到文件:
`envsubst < {{path/to/input_file}} > {{path/to/output_file}}`
- 从空格分隔的列表中替换输入文件中的环境变量:
`envsubst '{{$USER $SHELL $HOME}}' < {{path/to/input_file}}`