Debian Codegraph @

docs/content/en/functions/os/Getenv.md

raw
1 ---
2 title: os.Getenv
3 description: Returns the value of an environment variable, or an empty string if the environment variable is not set.
4 categories: []
5 keywords: []
6 params:
7 functions_and_methods:
8 aliases: [getenv]
9 returnType: string
10 signatures: [os.Getenv VARIABLE]
11 aliases: [/functions/getenv]
12 ---
13
14 ## Security
15
16 By default, when using the `os.Getenv` function Hugo allows access to:
17
18 - The `CI` environment variable
19 - Any environment variable beginning with `HUGO_`
20
21 To access other environment variables, adjust your project configuration. For example, to allow access to the `HOME` and `USER` environment variables:
22
23 {{< code-toggle file=hugo >}}
24 [security.funcs]
25 getenv = ['^HUGO_', '^CI$', '^USER$', '^HOME$']
26 {{< /code-toggle >}}
27
28 For more information see [configure security][].
29
30 ## Examples
31
32 ```go-html-template
33 {{ getenv "HOME" }} → /home/victor
34 {{ getenv "USER" }} → victor
35 ```
36
37 You can pass values when building your project:
38
39 ```sh
40 MY_VAR1=foo MY_VAR2=bar hugo
41
42 OR
43
44 export MY_VAR1=foo
45 export MY_VAR2=bar
46 hugo
47 ```
48
49 And then retrieve the values within a template:
50
51 ```go-html-template
52 {{ getenv "MY_VAR1" }} → foo
53 {{ getenv "MY_VAR2" }} → bar
54 ```
55
56 [configure security]: /configuration/security/