Thanks to visit codestin.com
Credit goes to www.scribd.com

0% found this document useful (0 votes)
60 views1 page

Reading Env in Golang

The document contains a Go program that retrieves and displays the value of the 'PAGER' environment variable. It checks if the variable exists, printing a message accordingly. If the variable is not set, it indicates that the environment variable does not exist.

Uploaded by

DataStage4You
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
60 views1 page

Reading Env in Golang

The document contains a Go program that retrieves and displays the value of the 'PAGER' environment variable. It checks if the variable exists, printing a message accordingly. If the variable is not set, it indicates that the environment variable does not exist.

Uploaded by

DataStage4You
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 1

// Go Playground

// https://go.dev/play/p/9wqZwtlDdQk

package main

import (
"fmt"
"os"
)

func main() {

// fetch Language env var


// If env exists, return value else return empty
fmt.Println("PAGER env:", os.Getenv("PAGER"))

// to check if Env exists or not


// if env var does not exists, retrun false else true
if val, ok := os.LookupEnv("PAGER"); ok == false {
fmt.Println("Env var does not exists.")
} else {
fmt.Println("Env val exists and value is:", val)
}

You might also like