posix

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 26, 2020 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cmd

type Cmd struct {
	*exec.Cmd
}

Cmd is the base of the POSIX commands.

func Alias

func Alias(name string, str string) *Cmd

Alias is the alias wrapper for the POSIX command.

see: http://pubs.opengroup.org/onlinepubs/9699919799/utilities/alias.html

Example
package main

import (
	"fmt"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Alias("foo", "echo 'Hello World'")
	fmt.Println(cmd)
}
Output:

alias foo='echo \'Hello World\''

func Command

func Command(name string, arg ...string) *Cmd

Command creates a new posix.Cmd.

Example
package main

import (
	"os"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Command("echo", "1")
	cmd.Stdout = os.Stdout
	if err := cmd.Run(); err != nil {
		panic(err)
	}
}
Output:

1

func Export

func Export(name string, word string) *Cmd

Export is the export wrapper for the POSIX command.

http://pubs.opengroup.org/onlinepubs/007904975/utilities/export.html

Example
package main

import (
	"fmt"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Export("FOO", "{\"foo\": 1}")
	fmt.Println(cmd)
}
Output:

export FOO="{\"foo\": 1}"

func PathExport

func PathExport(word string) *Cmd

PathExport returns the wrapper command `export PATH = ...`.

Example
package main

import (
	"fmt"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.PathExport("/bin:/sbin")
	fmt.Println(cmd)
}
Output:

export PATH="/bin:/sbin:$PATH"

func (*Cmd) String

func (cmd *Cmd) String() string

String returns command string.

Example
package main

import (
	"fmt"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Command("echo", "1")
	fmt.Println(cmd)
}
Output:

echo 1

type ShellScript added in v0.3.0

type ShellScript Cmd

func Shell

func Shell(commandString string) *ShellScript

Shell runs the POSIX command as a shell

http://pubs.opengroup.org/onlinepubs/009695399/utilities/sh.html TODO: Implement other options if there is a use case

Example
package main

import (
	"os"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Shell("echo $FOO")
	cmd.Stdout = os.Stdout
	cmd.Env = append(cmd.Env, "FOO=1")
	if err := cmd.Run(); err != nil {
		panic(err)
	}
}
Output:

1

func (*ShellScript) Run added in v0.3.0

func (shell *ShellScript) Run() error

Run shell script.

func (*ShellScript) String added in v0.3.0

func (shell *ShellScript) String() string

String returns body of shell script.

Example
package main

import (
	"fmt"

	"github.com/k-kinzal/aliases/pkg/posix"
)

func main() {
	cmd := posix.Shell("echo $FOO")
	fmt.Println(cmd)
}
Output:

echo $FOO

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL