如何暂停程序?

I want to realize the pause function like windows shell command pause. For example,

$ go run script.go 
Any key to continue...     //Then any key to continue

On windows, we can use the system command by golang function exec.Command(). But how about on Linux? I want to use the command read -n1 -p "Any key to continue" as a compromised one, but it doesn't work in the function exec.Command("read", "-n", "1"). I tested a lot but failed to know why.

Besides, do anyone know how to achieve the pause function just by golang language itself without using the external command?

Just read from stdin. The user would have to press enter for you program to continue. Or set the terminal into "raw" mode. For the later case, there's eg. nsf's termbox

Read a line from the standard input, then discard it (source):

bio := bufio.NewReader(os.Stdin)
line, hasMoreInLine, err := bio.ReadLine()

Am not sure if you can do that if you do not disable except you uncook then terminal (disable input buffering)> here is a simple solution to that

This is OS dependent to better ask the user the press enter. You also want to capture signals such as Ctrl+Z or Ctrl+C etc.

c := make(chan os.Signal)
d := make(chan bool)

// Capture Control
signal.Notify(c, os.Interrupt, os.Kill)

//Capture Enter
go func() {
    bio := bufio.NewReader(os.Stdin)
    bio.ReadByte()
    d <- true
}()


fmt.Println("Any key to continue... ")

// Block
select {
    case <- d :
    case <- c :
}

fmt.Println("Mission Completed")

Finally, I found the following methods:

In Linux Shell Script:

echo -ne "press any key to continue..."; stty -echo; read -n1; stty echo

In Golang for Linux (ref: https://stackoverflow.com/a/17278730/2507321):

package main

import (
    "fmt"
    "os"
    "os/exec"
)

func main() {
    // disable input buffering
    exec.Command("stty", "-F", "/dev/tty", "cbreak", "min", "1").Run()
    // do not display entered characters on the screen
    exec.Command("stty", "-F", "/dev/tty", "-echo").Run()

    var b []byte = make([]byte, 1)

    fmt.Printf("any key to continue...")
    os.Stdin.Read(b)
}

In Golang for windows:

exec.Command("cmd", "/C", "pause")