Skip to content

Instantly share code, notes, and snippets.

@mehmetahsen
Created December 21, 2020 19:01
Show Gist options
  • Save mehmetahsen/299f4157a839481bbfdd3b6100ab2ed2 to your computer and use it in GitHub Desktop.
Save mehmetahsen/299f4157a839481bbfdd3b6100ab2ed2 to your computer and use it in GitHub Desktop.
envsubst vs bash here-doc
#
# With envsubst
#
$ cat webadmin.ini.tpl # a template file is required
[User:${CUBERITE_USERNAME}]
Password=${CUBERITE_PASSWORD}
[WebAdmin]
Enabled=1
Ports=8080
$ export CUBERITE_USERNAME=admin #vars need to be exported
$ export CUBERITE_PASSWORD=cuberite
$ envsubst < webadmin.ini.tpl > webadmin.ini # neat and tidy single liner
$ cat webadmin.ini # result
[User:admin]
Password=cuberite
[WebAdmin]
Enabled=1
Ports=8080
#
# with bash here-doc
#
$ CUBERITE_USERNAME=admin # vars need not to be exported
$ CUBERITE_PASSWORD=cuberite
$ cat <<EOF > webadmini.ini # crowded but no other file required
[User:${CUBERITE_USERNAME}]
Password=${CUBERITE_PASSWORD}
[WebAdmin]
Enabled=1
Ports=8080
EOF
$ cat webadmin.ini # result
[User:admin]
Password=cuberite
[WebAdmin]
Enabled=1
Ports=8080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment