[Shell command] Expand environment variables with envsubst

Created on November 28, 2026

You can use the envsubst command to expand environment variables in text read from standard input.

For example, set the environment variable NAME as follows.

export NAME="Taro"

Then pass a string containing ${NAME} to envsubst.

printf 'Hello, ${NAME}!\n' | envsubst

The command produces the following output.

Hello, Taro!

envsubst replaces environment variables written as $NAME or ${NAME} with their current values.

References

Shell command