bash

package module
v0.0.0-...-c9ff703 Latest Latest
Warning

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

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Pipe

func Pipe(dir string, args ...[]string)

Pipe allows you to pipe multiple bash commands

[example (bash)]

echo "test" | tee -a "./test.txt"

[example (go)]

bash.Pipe(".", []string{"echo", "test"}, []string{"tee", "-a", "./test.txt"})

@dir: a directory to run the command in (set to an empty string to disable)

func PipeMultiDir

func PipeMultiDir(args ...[]string)

PipeMultiDir allows you to pipe multiple bash commands with a different directory for each of them

note: the first arg is the directory

[example]

bash.PipeMultiDir([]string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})

func PipeMultiDirEnv

func PipeMultiDirEnv(env []string, args ...[]string)

PipeMultiDirEnv is just like the 'PipeMultiDir' method, but it also allows you to add custom envirronment vars

note: the first arg is the directory

[example]

bash.PipeMultiDirEnv([]string{`MyEnvVar=CustomValue`}, []string{"/dir1", "cat", "test.txt"}, []string{"./dir2", "tee", "-a", "./test.txt"})

func Run

func Run(args []string, dir string, env []string, liveOutput ...bool) (output []byte, err error)

Run will run a bash command based on the given args

note: stdin is piped to the os logs

@dir: a directory to run the command in (set to an empty string to disable)
@env: an optional list of environment variables (set to nil to disable)

[optional]

@liveOutput[0]: set to true to pipe stdout and stderr to the os
@liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden

func RunRaw

func RunRaw(cmdStr string, dir string, env []string, liveOutput ...bool) (output []byte, err error)

RunRaw will run an unescaped (unquoted) bash command as a different user

this method uses `bash -c` to get around the auto quotes added by golang

note: user input is Not recommended for this method

note: stdin is piped to the os logs

@cmdStr: the command to run
@dir: a directory to run the command in (set to an empty string to disable)
@env: an optional list of environment variables (set to nil to disable)

[optional]

@liveOutput[0]: set to true to pipe stdout and stderr to the os
@liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden

func RunUser

func RunUser(cmdStr string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)

RunUser will run an unescaped (unquoted) bash command as a specified user

this method uses `runuser -l [user] -c`

note: user input is Not recommended for this method

note: stdin is piped to the os logs

@cmdStr: the command to run
@user: the username to run the command as
@dir: a directory to run the command in (set to an empty string to disable)
@env: an optional list of environment variables (set to nil to disable)

[optional]

@liveOutput[0]: set to true to pipe stdout and stderr to the os
@liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden

func RunUserFile

func RunUserFile(file string, args []string, user string, dir string, env []string, liveOutput ...bool) (output []byte, err error)

RunUserFile will run a bash file as a specified user

this method uses `pkexec --user [user]` to simulate a user in a normal desktop environment

note: user input is Not recommended for this method

note: stdin is piped to the os logs

@file: the file to run
@user: the username to run the command as
@dir: a directory to run the command in (set to an empty string to disable)
@env: an optional list of environment variables (set to nil to disable)

[optional]

@liveOutput[0]: set to true to pipe stdout and stderr to the os
@liveOutput[1]: set to false to only pipe stdout to the os, and keep stderr hidden

Types

This section is empty.

Jump to

Keyboard shortcuts

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