Documentation
¶
Overview ¶
Package bashexec provides helpers to execute bash code. What this primarily offers over directly writing e.g. `exec.Command("bash")` is:
- By default, all fragments are executed in "bash strict mode": http://redsymbol.net/articles/unofficial-bash-strict-mode/
- The code encourages adding a "name" for in-memory scripts, similar to e.g. Ansible tasks as well as many CI systems like Github actions
- The code to execute is piped to stdin instead of passed via `-c` which avoids argument length limits and makes the output of e.g. `ps` readable.
- Scripts are assumed synchronous, and stdin/stdout/stderr are passed directly instead of piped.
- We use prctl(PR_SET_PDEATHSIG) (assuming Linux) to lifecycle bind the script to the caller
Index ¶
Constants ¶
View Source
const StrictMode = "set -euo pipefail"
StrictMode enables http://redsymbol.net/articles/unofficial-bash-strict-mode/
Variables ¶
This section is empty.
Functions ¶
Types ¶
type BashRunner ¶
type BashRunner struct {
// contains filtered or unexported fields
}
BashRunner is a wrapper for executing in-memory bash scripts
func NewBashRunner ¶
func NewBashRunner(name, src string, args ...string) (*BashRunner, error)
NewBashRunner creates a bash executor from in-memory shell script.
func (*BashRunner) Exec ¶
func (r *BashRunner) Exec() error
Exec synchronously spawns the child process, passing stdin/stdout/stderr directly.
func (*BashRunner) Run ¶
func (r *BashRunner) Run() error
Run spawns the script, gathering stdout/stderr into a buffer that is displayed only on error.
Click to show internal directories.
Click to hide internal directories.