sh

package
v0.0.0-...-d459dd1 Latest Latest
Warning

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

Go to latest
Published: Oct 1, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package sh interprets a command line just like it is done in the Bash shell.

The main function is Run which lets to call to system commands under a new process. It handles pipes, environment variables, and does pattern expansion.

Index

Constants

View Source
const PATH = "/sbin:/bin:/usr/sbin:/usr/bin"

Variables

View Source
var (
	BOOT  bool // does the script is being run during boot?
	DEBUG bool

	Log = log.New(ioutil.Discard, "", 0)
)
View Source
var Debug bool

Debug shows debug messages in functions like Run.

Functions

func CloseLogger

func CloseLogger() error

CloseLogger closes the log file.

func Run

func Run(command string) (output []byte, err error)

Run executes external commands just like RunWithMatch, but does not return the boolean `match`.

func RunWithMatch

func RunWithMatch(command string) (output []byte, match bool, err error)

RunWithMatch executes external commands with access to shell features such as filename wildcards, shell pipes, environment variables, and expansion of the shortcut character "~" to home directory.

This function avoids to have execute commands through a shell since an unsanitized input from an untrusted source makes a program vulnerable to shell injection, a serious security flaw which can result in arbitrary command execution.

The most of commands return a text in output or an error if any. `match` is used in commands like *grep*, *find*, or *cmp* to indicate if the serach is matched.

func RunWithMatchf

func RunWithMatchf(format string, args ...interface{}) ([]byte, bool, error)

RunWithMatchf is like RunWithMatch, but formats its arguments according to the format. Analogous to Printf().

func Runf

func Runf(format string, args ...interface{}) ([]byte, error)

Runf is like Run, but formats its arguments according to the format. Analogous to Printf().

func StartLogger

func StartLogger()

StartLogger initializes the log file.

func Sudo

func Sudo()

Sudo calls to command sudo. If anything command needs to use sudo, then could be used this function at the beginning so there is not to wait until that it been requested later.

Types

This section is empty.

Jump to

Keyboard shortcuts

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