environment variables _ golang

Environment variables are a univerial mechanism for conveying configuration information to Unix programs. Let‘s look at how to set, get, and list environmant variables

package main

import (
    "fmt"
    "os"
    "strings"
)

func main() {

    os.Setenv("FOO", "1")
    fmt.Println("FOO:", os.Getenv("FOO"))
    fmt.Println("BAR:", os.Getenv("BAR"))

    for _, e := range os.Environ() {
        pair := strings.Split(e, "=")
        fmt.Println(pair[0])
    }
}
FOO: 1
BAR: 2
BAR
TERM_PROGRAM
SHELL
TERM
TMPDIR
Apple_PubSub_Socket_Render
TERM_PROGRAM_VERSION
OLDPWD
TERM_SESSION_ID
USER
SSH_AUTH_SOCK
__CF_USER_TEXT_ENCODING
PATH
PWD
XPC_FLAGS
XPC_SERVICE_NAME
SHLVL
HOME
LOGNAME
LC_CTYPE
GOPATH
_
FOO

总结 :

  1 : ....

时间: 2024-10-19 11:22:05

environment variables _ golang的相关文章

variables _ golang

在 golang 中, 变量是通过编译器声明和使用的,并且编译器会进行相应的类型检查 package main import ( "fmt" ) func main() { var a string = "initial" fmt.Println(a) var b, c int = 1, 2 fmt.Println(b, c) var d = true fmt.Println(d) var e int fmt.Println(e) f := "short&

CVE: 2014-6271 Bash Specially-crafted Environment Variables Code Injection Vulnerability Analysis

目录 1. 漏洞的起因 2. 漏洞原理分析 3. 漏洞的影响范围 4. 漏洞的POC.测试方法 5. 漏洞的修复Patch 1. 漏洞的起因 这个漏洞的起因源自于Bash(Bourne Again SHell)的ENV指令 http://ss64.com/bash/env.html env: Display, set, or remove environment variables, Run a command in a modified environment. Syntax env [OPT

[Now] Configure secrets and environment variables with Zeit’s Now

Often your project will require some secret keys or tokens - for instance, API keys or database authentication information. Learn how to safely and easily deploy secrets to now, and how to expose them as environment variables that your applications c

How to keep Environment Variables when Using SUDO

The trick is to add environment variables to sudoers file via sudo visudo command and add these lines: Defaults env_keep += "ftp_proxy http_proxy https_proxy no_proxy" from: http://stackoverflow.com/questions/8633461/how-to-keep-environment-vari

[Shell&Mac&Environment variables]自己常用的Mac(或者说Linux)Shell命令小结,含Mac使用zsh shell的环境变量的有关配置方法

今天在使用tomcat的配置的时候,我用的mac,要是用到一些命令去配置tomcat. 问题来了: 我每次要去启动tomcat服务特别麻烦,因为我要先进入tomcat所在的文件目录,或者不进入使用~/,但是因为我把tomcat放到了一个比较“深“的文件夹里,所以命令显得又丑又长. 问题解决方案: 1.使用环境变量(修改.bashrc的方法) a.先查看自己的Mac目前正在用的是什么shell echo $SHELL 返回结果类似如下图 这里我是zsh,,也许你是bash,不过没关系,配置环境变量

Environment Variables

https://msdn.microsoft.com/en-us/library/windows/desktop/ms682653(v=vs.85).aspx Every process has an environment block that contains a set of environment variables and their values. There are two types of environment variables: user environment varia

Linux environment variables (环境变量)

Environment variables are often used to store a list of paths of where to search for executables, libraries, and so on. 环境变量通常存放一堆路径,这些路径用来搜索可执行文件.动态链接库,等等. Examples are $PATH, $LD_LIBRARY_PATH, 可以通过 echo 命令来查看: [[email protected] ~]# echo $PATH /usr

errors _ golang

In Go it's idiomatic to communicate errors via an explicit, separate return value. this constrasts errors via an explicit, separate return value. This constrasts with the exceptions used in languages like Java and Ruby and the overloaded single resul

linux environment variables summary.

link source: https://wiki.archlinux.org/index.php/environment_variables Setting variables: Globally: edit /etc/profile, /etc/bash.bashrc, /etc/environment. Per User: ~/.bashrc, ~/.profile, ~/.bash_login, ~/.bash_logout