...

Source file src/github.com/codeskyblue/go-sh/example/example1.go

Documentation: github.com/codeskyblue/go-sh/example

     1  package main
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  
     7  	"github.com/codeskyblue/go-sh"
     8  )
     9  
    10  func main() {
    11  	sh.Command("echo", "hello").Run()
    12  	out, err := sh.Command("echo", "hello").Output()
    13  	if err != nil {
    14  		log.Fatal(err)
    15  	}
    16  	fmt.Println("output is", string(out))
    17  
    18  	var a int
    19  	sh.Command("echo", "2").UnmarshalJSON(&a)
    20  	fmt.Println("a =", a)
    21  
    22  	s := sh.NewSession()
    23  	s.Alias("hi", "echo", "hi")
    24  	s.Command("hi", "boy").Run()
    25  
    26  	fmt.Print("pwd = ")
    27  	s.Command("pwd", sh.Dir("/")).Run()
    28  
    29  	if !sh.Test("dir", "data") {
    30  		sh.Command("echo", "mkdir", "data").Run()
    31  	}
    32  
    33  	sh.Command("echo", "hello", "world").
    34  		Command("awk", `{print "second arg is "$2}`).Run()
    35  	s.ShowCMD = true
    36  	s.Command("echo", "hello", "world").
    37  		Command("awk", `{print "second arg is "$2}`).Run()
    38  
    39  	s.SetEnv("BUILD_ID", "123").Command("bash", "-c", "echo $BUILD_ID").Run()
    40  	s.Command("bash", "-c", "echo current shell is $SHELL").Run()
    41  }
    42  

View as plain text