How to get environment variable PS1 by golang?

泄露秘密 提交于 2021-02-07 19:44:49

问题


PS1 is an environment variable for bash prompt. I can get this by echo $PS1

I try to use os.Getenv to get PS1 but returns nothing:

package main

import (
  "fmt"
  "os"
)

func main() {
  fmt.Println(os.Getenv("PS1"))
}

Why does this happen and how should I fix this? Thanks.


回答1:


PS1 is probably not exported, meaning it won't show up in sub-processes of bash

try

export PS1

before you run your app

you could also do

PS1=$PS1 app

to set it specifically in the sub process



来源:https://stackoverflow.com/questions/29364178/how-to-get-environment-variable-ps1-by-golang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!