2019-10-21 04:22:28 -04:00
|
|
|
---
|
|
|
|
title: getenv
|
2021-12-08 02:42:31 -05:00
|
|
|
description: Returns the value of an environment variable, or an empty string if the environment variable is not set.
|
2019-10-21 04:22:28 -04:00
|
|
|
date: 2017-02-01
|
|
|
|
publishdate: 2017-02-01
|
2021-12-08 02:42:31 -05:00
|
|
|
lastmod: 2021-11-26
|
2019-10-21 04:22:28 -04:00
|
|
|
categories: [functions]
|
|
|
|
menu:
|
|
|
|
docs:
|
|
|
|
parent: "functions"
|
|
|
|
keywords: []
|
2021-12-08 02:42:31 -05:00
|
|
|
signature: ["os.Getenv VARIABLE", "getenv VARIABLE"]
|
2019-10-21 04:22:28 -04:00
|
|
|
workson: []
|
|
|
|
hugoversion:
|
|
|
|
relatedfuncs: []
|
|
|
|
deprecated: false
|
|
|
|
aliases: []
|
|
|
|
---
|
2021-12-08 02:42:31 -05:00
|
|
|
Examples:
|
2019-10-21 04:22:28 -04:00
|
|
|
|
2021-12-08 02:42:31 -05:00
|
|
|
```go-html-template
|
|
|
|
{{ os.Getenv "HOME" }} --> /home/victor
|
|
|
|
{{ os.Getenv "USER" }} --> victor
|
2019-10-21 04:22:28 -04:00
|
|
|
```
|
2021-12-08 02:42:31 -05:00
|
|
|
|
|
|
|
You can pass values when building your site:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
MY_VAR1=foo MY_VAR2=bar hugo
|
|
|
|
|
|
|
|
OR
|
|
|
|
|
|
|
|
export MY_VAR1=foo
|
|
|
|
export MY_VAR2=bar
|
|
|
|
hugo
|
2019-10-21 04:22:28 -04:00
|
|
|
```
|
|
|
|
|
2021-12-08 02:42:31 -05:00
|
|
|
And then retrieve the values within a template:
|
|
|
|
|
|
|
|
```go-html-template
|
|
|
|
{{ os.Getenv "MY_VAR1" }} --> foo
|
|
|
|
{{ os.Getenv "MY_VAR2" }} --> bar
|
|
|
|
```
|