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
- Variables
- func CloseLogger() error
- func Run(command string) (output []byte, err error)
- func RunWithMatch(command string) (output []byte, match bool, err error)
- func RunWithMatchf(format string, args ...interface{}) ([]byte, bool, error)
- func Runf(format string, args ...interface{}) ([]byte, error)
- func StartLogger()
- func Sudo()
Constants ¶
const PATH = "/sbin:/bin:/usr/sbin:/usr/bin"
Variables ¶
var ( BOOT bool // does the script is being run during boot? DEBUG bool Log = log.New(ioutil.Discard, "", 0) )
var Debug bool
Debug shows debug messages in functions like Run.
Functions ¶
func Run ¶
Run executes external commands just like RunWithMatch, but does not return the boolean `match`.
func RunWithMatch ¶
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 ¶
RunWithMatchf is like RunWithMatch, but formats its arguments according to the format. Analogous to Printf().
Types ¶
This section is empty.