Documentation
¶
Overview ¶
Package shellescape provides functions to escape strings for use in posix shell commands.
It is a drop-in replacement for gopkg.in/alessio/shellescape.v1.
Additionally an Unquote function is provided.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // ErrMismatchedQuotes is returned when the input string has mismatched quotes when unquoting. ErrMismatchedQuotes = errors.New("mismatched quotes") // ErrTrailingBackslash is returned when the input string ends with a trailing backslash. ErrTrailingBackslash = errors.New("trailing backslash") )
Functions ¶
func Quote ¶
Quote safely encloses a string in single quotes for shell usage.
Example ¶
This example demonstrates how to use shellescape.Quote to escape a string for use as an argument to a shell command.
package main
import (
"fmt"
"github.com/k0sproject/rig/v2/sh/shellescape"
)
func main() {
quoted := shellescape.Quote("value with spaces")
fmt.Println(quoted)
}
Output: 'value with spaces'
func QuoteCommand ¶
QuoteCommand safely quotes and joins a list of strings for use as a shell command.
Example ¶
This example demonstrates how to use shellescape.QuoteCommand to escape a command and its arguments for use in a shell command.
package main
import (
"fmt"
"github.com/k0sproject/rig/v2/sh/shellescape"
)
func main() {
quoted := shellescape.QuoteCommand([]string{"ls", "-l", "file with space"})
fmt.Println(quoted)
}
Output: ls -l 'file with space'
func StripUnsafe ¶
StripUnsafe removes non-printable runes from a string.
Types ¶
This section is empty.
Click to show internal directories.
Click to hide internal directories.