Skip to content

Instantly share code, notes, and snippets.

@k4ml
Last active October 14, 2018 05:37
Show Gist options
  • Select an option

  • Save k4ml/ee9129d5dbf7ec06e8115a1d8b127905 to your computer and use it in GitHub Desktop.

Select an option

Save k4ml/ee9129d5dbf7ec06e8115a1d8b127905 to your computer and use it in GitHub Desktop.

Revisions

  1. Kamal Mustafa revised this gist Oct 14, 2018. 2 changed files with 30 additions and 28 deletions.
    28 changes: 0 additions & 28 deletions input.go
    Original file line number Diff line number Diff line change
    @@ -1,28 +0,0 @@
    // https://tutorialedge.net/golang/reading-console-input-golang/
    import (
    "bufio"
    "fmt"
    "os"
    "strings"
    )

    func main() {
    reader := bufio.NewReader(os.Stdin)
    fmt.Println("Simple Shell")
    fmt.Println("---------------------")

    for {
    fmt.Print("-> ")
    text, _ := reader.ReadString('\n')
    // convert CRLF to LF
    text = strings.Replace(text, "\n", "", -1)

    if text == "\\q" {
    os.Exit(0)
    }
    if strings.Compare("hi", text) == 0 {
    fmt.Println("hello, Yourself")
    }
    }

    }
    30 changes: 30 additions & 0 deletions main.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,30 @@
    // https://tutorialedge.net/golang/reading-console-input-golang/
    package main

    import (
    "bufio"
    "fmt"
    "os"
    "strings"
    )

    func main() {
    reader := bufio.NewReader(os.Stdin)
    fmt.Println("Simple Shell")
    fmt.Println("---------------------")

    for {
    fmt.Print("-> ")
    text, _ := reader.ReadString('\n')
    // convert CRLF to LF
    text = strings.Replace(text, "\n", "", -1)

    if text == "\\q" {
    os.Exit(0)
    }
    if strings.Compare("hi", text) == 0 {
    fmt.Println("hello, Yourself")
    }
    }

    }
  2. k4ml created this gist Oct 14, 2018.
    28 changes: 28 additions & 0 deletions input.go
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,28 @@
    // https://tutorialedge.net/golang/reading-console-input-golang/
    import (
    "bufio"
    "fmt"
    "os"
    "strings"
    )

    func main() {
    reader := bufio.NewReader(os.Stdin)
    fmt.Println("Simple Shell")
    fmt.Println("---------------------")

    for {
    fmt.Print("-> ")
    text, _ := reader.ReadString('\n')
    // convert CRLF to LF
    text = strings.Replace(text, "\n", "", -1)

    if text == "\\q" {
    os.Exit(0)
    }
    if strings.Compare("hi", text) == 0 {
    fmt.Println("hello, Yourself")
    }
    }

    }