title: How to change the shell's current working directory in Go?
body: <p>I want implement the <code>cd</code> command with Go, <code>main.go</code>:</p>
  
  <pre><code>func main() {
      flag.Parse()
      if flag.NArg() == 0 {
          curUser, err := user.Current()
          if err != nil {
              log.Fatal(err)
          }
          os.Chdir(curUser.HomeDir)
          // or like this
          // cmd := exec.Command("cd", curUser.HomeDir)
          fmt.Println(os.Getwd())   // ok in application
      }
  }
  </code></pre>
  
  <p>But when I run <code>go run main.go</code> in shell, it still not switch to my home directory.</p>
  
  <p>So how can I change my working directory in shell by running go files?</p>
  
  <p><img src="https://i.stack.imgur.com/1ZlQU.jpg" alt="code running"></p>