×

Golang Tutorial

Golang Reference

Golang Programs

Golang Practice

Golang Miscellaneous

Golang os.Clearenv() Function with Examples

Golang | os.Clearenv() Function: Here, we are going to learn about the Clearenv() function of the os package with its usages, syntax, and examples.
Submitted by IncludeHelp, on November 16, 2021

os.Clearenv()

In the Go language, the os package provides a platform-independent interface to operating system (Unix-like) functionality. The Clearenv() function is an inbuilt function of the os package, it is used to delete all environment variables.

It accepts nothing.

Syntax

func Clearenv()

Parameters

  • None

Return Value

The return type of the os.Clearenv() function nothing.

Example

// Golang program to demonstrate the
// example of Clearenv() function

package main

import (
	"fmt"
	"os"
)

func main() {
	// Getting the environment variables
	// before clearing environment
	fmt.Println("Environment before Clearenv()...")
	fmt.Println(os.Environ())

	// clearing environment
	os.Clearenv()

	// Again, getting the environment variables
	// after clearing environment
	fmt.Println("Environment after Clearenv()...")
	fmt.Println(os.Environ())
}

Output:

Environment before Clearenv()...
[HOSTNAME=707a1fbd12d9 PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin HOME=/root]
Environment after Clearenv()...
[]

Golang os Package »




Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.