• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

escargs/H05-Jan-2017-

.gitignoreH A D05-Jan-2017266

.travis.ymlH A D05-Jan-201726

AUTHORSH A D05-Jan-201737

LICENSEH A D05-Jan-20171.1 KiB

README.mdH A D05-Jan-20171.7 KiB

example_test.goH A D05-Jan-2017446

shellescape.goH A D05-Jan-2017969

shellescape_test.goH A D05-Jan-20171.1 KiB

README.md

1[![GoDoc](https://godoc.org/github.com/alessio/shellescape?status.svg)](https://godoc.org/github.com/alessio/shellescape)
2[![Travis-CI Status](https://api.travis-ci.org/alessio/shellescape.png?branch=master)](http://travis-ci.org/#!/alessio/shellescape)
3[![Coverage](http://gocover.io/_badge/github.com/alessio/shellescape)](http://gocover.io/github.com/alessio/shellescape)
4# shellescape
5Escape arbitrary strings for safe use as command line arguments.
6## Contents of the package
7
8This package provides the `shellescape.Quote()` function that returns a
9shell-escaped copy of a string. This functionality could be helpful
10in those cases where it is known that the output of a Go program will
11be appended to/used in the context of shell programs' command line arguments.
12
13This work was inspired by the Python original package [shellescape]
14(https://pypi.python.org/pypi/shellescape).
15
16## Usage
17
18The following snippet shows a typical unsafe idiom:
19
20```go
21package main
22
23import (
24	"fmt"
25	"os"
26)
27
28func main() {
29	fmt.Printf("ls -l %s\n", os.Args[1])
30}
31```
32_[See in Go Playground](https://play.golang.org/p/Wj2WoUfH_d)_
33
34Especially when creating pipeline of commands which might end up being
35executed by a shell interpreter, tt is particularly unsafe to not
36escape arguments.
37
38`shellescape.Quote()` comes in handy and to safely escape strings:
39
40```go
41package main
42
43import (
44        "fmt"
45        "os"
46
47        "gopkg.in/alessio/shellescape.v1"
48)
49
50func main() {
51        fmt.Printf("ls -l %s\n", shellescape.Quote(os.Args[1]))
52}
53```
54_[See in Go Playground](https://play.golang.org/p/HJ_CXgSrmp)_
55
56## The escargs utility
57__escargs__ reads lines from the standard input and prints shell-escaped versions. Unlinke __xargs__, blank lines on the standard input are not discarded.
58