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