pogosh

package
Version: v7.0.0+incompatible Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2020 License: BSD-3-Clause Imports: 8 Imported by: 3

Documentation

Overview

Package pogosh implements a small POSIX-compatible shell.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BuiltinExit

func BuiltinExit(s *State, cmd *Cmd)

BuiltinExit implements the "exit" builtin.

func DefaultBuiltins

func DefaultBuiltins() map[string]Builtin

DefaultBuiltins lists all the available builtins.

Types

type Arithmetic

type Arithmetic struct {
	// contains filtered or unexported fields
}

Arithmetic computes value in $((...)) expression. TODO: why public?

type Builtin

type Builtin = func(*State, *Cmd)

Builtin is the function used to run a builtin.

type Cmd

type Cmd struct {
	os.ProcAttr
	// contains filtered or unexported fields
}

Cmd is a builtin command to run.

type Overrides

type Overrides struct {
	Chdir   func(dir string) error
	Environ func() []string
	Exit    func(code int)
}

Overrides change the behaviour of builtins.

func DefaultOverrides

func DefaultOverrides() Overrides

DefaultOverrides creates a new default overrides.

type State

type State struct {
	IsInteractive bool

	Builtins map[string]func(*State, *Cmd)
	Aliases  map[string]string

	Overrides Overrides
	// contains filtered or unexported fields
}

State holds data on the current interpreter execution.

func DefaultState

func DefaultState() State

DefaultState creates a new default state.

func (*State) Run

func (s *State) Run(script string) (exitCode int, err error)

Run executes the given fragment of shell.

There are three circumstances for this function to return:

1. There is a shell error (compiler error, file not found, ...) 2. The script calls the exit builtin. 3. The script reaches the end of input.

In the case the shell script execs another process, this function will not return (unless the Exec function is appropriately overriden).

func (*State) RunFile

func (s *State) RunFile(filename string) (int, error)

RunFile is a convenient wrapper around Run.

type Var

type Var struct {
	Value string
}

Var holds information on shell variable.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
t or T : Toggle theme light dark auto
y or Y : Canonical URL