summaryrefslogtreecommitdiffstats
path: root/docs/content/en/functions/os/Getenv.md
blob: 04215e6c36a221f8167f9fec57bf6b45a2bde483 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
---
title: os.Getenv
description: Returns the value of an environment variable, or an empty string if the environment variable is not set.
categories: []
keywords: []
params:
  functions_and_methods:
    aliases: [getenv]
    returnType: string
    signatures: [os.Getenv VARIABLE]
aliases: [/functions/getenv]
---

## Security

By default, when using the `os.Getenv` function Hugo allows access to:

- The `CI` environment variable
- Any environment variable beginning with `HUGO_`

To access other environment variables, adjust your site configuration. For example, to allow access to the `HOME` and `USER` environment variables:

{{< code-toggle file=hugo >}}
[security.funcs]
getenv = ['^HUGO_', '^CI$', '^USER$', '^HOME$']
{{< /code-toggle >}}

For more information see [configure security](/configuration/security).

## Examples

```go-html-template
{{ getenv "HOME" }} → /home/victor
{{ getenv "USER" }} → victor
```

You can pass values when building your site:

```sh
MY_VAR1=foo MY_VAR2=bar hugo

OR

export MY_VAR1=foo
export MY_VAR2=bar
hugo
```

And then retrieve the values within a template:

```go-html-template
{{ getenv "MY_VAR1" }} → foo
{{ getenv "MY_VAR2" }} → bar
```