如何编写可以切换到bash的shell?

I want to switch to the bash shell from my custom shell in go.

I am not sure how to sleep my parent process (custom shell) and switch to the child process (bash)

This is my part of the code.

    cmd := exec.Command("bash", "-c", "/bin/bash")
    stdoutStderr, err := cmd.CombinedOutput()
    if err != nil {
        fmt.Printf(err.Error())
    }
    fmt.Printf("%s
", stdoutStderr)

I want to do it as follows:

myshell >> /bin/bash
$ /bin/myshell
myshell >>

the code is exec but not fork

    binary, lookErr := exec.LookPath("/bin/bash")
    if lookErr != nil {
        panic(lookErr)
    }

    args := []string{"/bin/bash"}

    env := os.Environ()

    execErr := syscall.Exec(binary, args, env)
    if execErr != nil {
        panic(execErr)
    }

so if I exit the bash shell, of course, my custom shell is killed.

myshell> bash
bash-3.2$ exit
exit

This is a recipe for how to stop a process and let the parent shell process take over control. I'm not sure if you can use it to do the opposite.

The idea is to send a stop signal to yourself.

pid := os.Getpid()
process, err := os.FindProcess(pid)
if err != nil {
    err = errors.Wrapf(err, "error pausing process %+v", process)
    return
}
process.Signal(syscall.SIGSTOP)

Source https://github.com/grzegorz-zur/bare-minimum/blob/95fb116631b6146707c47455d8ffce6bb5b8717c/editor.go#L152

Earlier you need to listen in a goroutine to continue signal to reinitialize your process if needed

signals := make(chan os.Signal, 1)
signal.Notify(signals, syscall.SIGCONT, syscall.SIGTERM)
for signal := range signals {
    switch signal {
    case syscall.SIGCONT:
        // reinitialize
    case syscall.SIGTERM:
        // stop
    }
}

Source https://github.com/grzegorz-zur/bare-minimum/blob/95fb116631b6146707c47455d8ffce6bb5b8717c/editor.go#L87

I have resolved this problem by this way.

package main

import (
    "os/exec"
)

func main() {
    cmd := exec.Command("sh", "-c", "bash")
    cmd.Stdout = os.Stdout
    cmd.Stdin = os.Stdin
    cmd.Stderr = os.Stderr

    cmd.Run()
}