From c6516bfc680167cdde22171cec859fe7a42aff93 Mon Sep 17 00:00:00 2001 From: Steven Polley Date: Sat, 18 Aug 2018 15:52:39 -0600 Subject: [PATCH] Initial commit --- .vscode/tasks.json | 17 +++++++++++++++++ main.go | 33 +++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+) create mode 100644 .vscode/tasks.json create mode 100644 main.go diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..2bd70fe --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,17 @@ +{ + // See https://go.microsoft.com/fwlink/?LinkId=733558 + // for the documentation about the tasks.json format + "version": "2.0.0", + "tasks": [ + { + "label": "echo", + "type": "shell", + "command": "go run main.go", + "group": { + "kind": "build", + "isDefault": true + }, + "problemMatcher": [] + } + ] +} \ No newline at end of file diff --git a/main.go b/main.go new file mode 100644 index 0000000..52f4ad2 --- /dev/null +++ b/main.go @@ -0,0 +1,33 @@ +package main + +import ( + "bufio" + "fmt" + "log" + "os" + "strings" +) + +func main() { + f, err := os.Open("env.sh") + if err != nil { + log.Fatalf("could not open env.sh: %s", err) + } + + s := bufio.NewScanner(f) + fmt.Println("\tenvironment:") + + for s.Scan() { + if strings.HasPrefix(s.Text(), "export ") { + //Store the variable name in v[0] and the value in v[1] + //then strip the quotes from the value. + v := strings.Split(s.Text()[7:], "=") + v[1] = strings.TrimSuffix(v[1], "\"") + v[1] = strings.TrimPrefix(v[1], "\"") + fmt.Printf("\t\t- %s=%s\n", v[0], v[1]) + } + } + if err := s.Err(); err != nil { + log.Fatalf("reading env.sh: %s", err) + } +}