sh

package
v0.1.10 Latest Latest
Warning

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

Go to latest
Published: Jan 30, 2026 License: MIT Imports: 49 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var BuiltinCommands = []string{
	"true", "false", "exit", "set", "shift", "unset",
	"echo", "printf", "break", "continue", "pwd", "cd",
	"wait", "builtin", "trap", "type", "source", ".", "command",
	"dirs", "pushd", "popd", "umask", "alias", "unalias",
	"fg", "bg", "getopts", "eval", "test", "[", "exec",
	"return", "read", "mapfile", "readarray", "shopt",
}

bash commands

View Source
var CoreUtilsCommands = []string{
	"base64", "basename", "cat", "chmod", "cp", "date", "dirname", "find", "gzip", "head", "ls", "mkdir",
	"mktemp", "mv", "rm", "shasum", "sleep", "tac", "tail", "tar", "time", "touch", "wget", "xargs",
}

internal commands

Functions

func ClearAllEnv

func ClearAllEnv(keeps []string)

ClearAllEnv clears all environment variables except for the keeps

func DecodeFileFlag

func DecodeFileFlag(flag int) string

func DecodeFilePerm

func DecodeFilePerm(perm fs.FileMode) string

func Gosh

func Gosh(ctx context.Context, vs *VirtualSystem, script string, args []string) error

Gosh executes a script provided in the argument. If no arguments are provided, it will execute in interactive mode if standard input supports it. This function manages errors and exits appropriately.

func IsCoreUtils

func IsCoreUtils(s string) bool

func IsShell

func IsShell(s string) bool

return true if the last elemment is or ends in sh/bash

func ParseFlags

func ParseFlags(args []string) (string, string, []string)

Parse parses flag definitions from the argument list, which should not include the command name. Return root, script, and remaining non flag args

func Run

func Run(parent context.Context, vs *VirtualSystem, script string, args []string) error

func RunCoreUtils

func RunCoreUtils(ctx context.Context, vs *VirtualSystem, args []string) (bool, error)

func VirtualCallHandlerFunc added in v0.1.10

func VirtualCallHandlerFunc(vs *VirtualSystem) interp.CallHandlerFunc

TODO set: -e Exit immediately if a command exits with a non-zero status. -o option-name

			pipefail   the return value of a pipeline is the status of
                       the last command to exit with a non-zero status,
                       or zero if no command exited with a non-zero status

-u Treat unset variables as an error when substituting. -x Print commands and their arguments as they are executed.

func VirtualExecHandler

func VirtualExecHandler(vs *VirtualSystem) func(next interp.ExecHandlerFunc) interp.ExecHandlerFunc

func VirtualOpenHandler

func VirtualOpenHandler(vs *VirtualSystem) interp.OpenHandlerFunc

func VirtualReadDirHandler2

func VirtualReadDirHandler2(vs *VirtualSystem) interp.ReadDirHandlerFunc2

func VirtualStatHandler

func VirtualStatHandler(vs *VirtualSystem) interp.StatHandlerFunc

Types

type ExecHandler

type ExecHandler func(context.Context, []string) (bool, error)

func NewDummyExecHandler

func NewDummyExecHandler(vs *VirtualSystem) ExecHandler

type IOE

type IOE struct {
	Stdin  io.Reader
	Stdout io.Writer
	Stderr io.Writer
}

standard IO

func NewStdIOE

func NewStdIOE() *IOE

func NewStringIOE

func NewStringIOE(s string) *IOE

type StringIOE

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

type VirtualSystem

type VirtualSystem struct {
	IOE *IOE

	Workspace vfs.Workspace
	System    vos.System

	ExecHandler ExecHandler

	MaxTimeout int
}

func NewLocalSystem

func NewLocalSystem(roots []string, ioe *IOE) (*VirtualSystem, error)

func NewVirtualSystem

func NewVirtualSystem(ws vfs.Workspace, s vos.System, ioe *IOE) *VirtualSystem

func (*VirtualSystem) NewRunner

func (vs *VirtualSystem) NewRunner(opts ...interp.RunnerOption) (*interp.Runner, error)

func (*VirtualSystem) RunInteractive

func (vs *VirtualSystem) RunInteractive(ctx context.Context) error

func (*VirtualSystem) RunPath

func (vs *VirtualSystem) RunPath(ctx context.Context, path string) error

func (*VirtualSystem) RunReader

func (vs *VirtualSystem) RunReader(ctx context.Context) error

func (*VirtualSystem) RunScript

func (vs *VirtualSystem) RunScript(ctx context.Context, script string) error

Jump to

Keyboard shortcuts

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