shellescape: github.com/alessio/shellescape Index | Examples | Files | Directories

package shellescape

import "github.com/alessio/shellescape"

Package shellescape provides the shellescape.Quote to escape arbitrary strings for a safe use as command line arguments in the most common POSIX shells.

The original Python package which this work was inspired by can be found at https://pypi.python.org/pypi/shellescape.

Index

Examples

Package Files

shellescape.go

func Quote Uses

func Quote(s string) string

Quote returns a shell-escaped version of the string s. The returned value is a string that can safely be used as one token in a shell command line.

Code:

filename := "myfile; rm -rf /"
prog := "/bin/ls"
unescapedCommand := strings.Join([]string{prog, filename}, " ")
escapedCommand := strings.Join([]string{prog, shellescape.Quote(filename)}, " ")

fmt.Println(unescapedCommand)
fmt.Println(escapedCommand)

Output:

/bin/ls myfile; rm -rf /
/bin/ls 'myfile; rm -rf /'

Directories

PathSynopsis
cmd/escargsescargs reads lines from the standard input and prints shell-escaped versions.

Package shellescape imports 2 packages (graph) and is imported by 8 packages. Updated 2020-03-02. Refresh now. Tools for package owners.