Last active
December 12, 2020 18:52
-
-
Save gordcurrie/465053da9b17f031ef6b62df33312ff5 to your computer and use it in GitHub Desktop.
Using envsubst to generate code.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # if called with no params sets the value of $1 to "World" | |
| if [ -z $1 ] | |
| then | |
| set "World" | |
| fi | |
| # sets the env var used in template | |
| export yourName=$1 \ | |
| attribute="cool" | |
| # subsitues the variables in the template with the env vars | |
| # and outputs to the new file | |
| envsubst < ./hello.go.tmpl > ./hello${1}.go |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Println("Hello ${yourName}! You are ${attribute}.") | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| package main | |
| import "fmt" | |
| func main() { | |
| fmt.Println("Hello Gord! You are cool.") | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment