shell

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

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

Go to latest
Published: Nov 15, 2019 License: MPL-2.0 Imports: 1 Imported by: 170

README

shell

GoDoc Build Status License

Escape command line parameters to be executed on the shell.

Ported from https://github.com/xxorax/node-shell-escape.

Usage

package main

import (
	"fmt"

	"github.com/taskcluster/shell"
)

func main() {
	fmt.Println(
		shell.Escape(
			"curl",
			"-v",
			"-H",
			"Location;",
			"-H",
			"User-Agent: dave#10",
			"http://www.daveeddy.com/?name=dave&age=24",
		),
	)
}

produces...

curl -v -H 'Location;' -H 'User-Agent: dave#10' 'http://www.daveeddy.com/?name=dave&age=24'

Documentation

Overview

Package shell provides safe escaping of command line tokens

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(tokens ...string) (escaped string)
Example (Basic)
package main

import (
	"fmt"

	"github.com/taskcluster/shell"
)

func out(args ...string) {
	fmt.Println(shell.Escape(args...))
}

func main() {
	out(`echo`, `hello!`, `how are you doing $USER`, `"double"`, `'single'`)
	out(`'''`)
	out(`'>''`)
	out(`curl`, `-v`, `-H`, `Location;`, `-H`, `User-Agent: dave#10`, `http://www.daveeddy.com/?name=dave&age=24`)
	out(`echo`, `hello\\nworld`)
	out(`echo`, `hello:world`)
	out(`echo`, `--hello=world`)
	out(`echo`, `hello\\tworld`)
	out(`echo`, `\thello\nworld'`)
	out(`echo`, `hello  world`)
	out(`echo`, `hello`, `world`)
	out(`echo`, "hello\\\\'", "'\\\\'world")
	out(`echo`, "hello", "world\\")
	out(`abc`, ``, `def`)

}
Output:

echo 'hello!' 'how are you doing $USER' '"double"' \'single\'
\'\'\'
\''>'\'\'
curl -v -H 'Location;' -H 'User-Agent: dave#10' 'http://www.daveeddy.com/?name=dave&age=24'
echo 'hello\\nworld'
echo hello:world
echo --hello=world
echo 'hello\\tworld'
echo '\thello\nworld'\'
echo 'hello  world'
echo hello world
echo 'hello\\'\' \''\\'\''world'
echo hello 'world\'
abc '' def

Types

This section is empty.

Jump to

Keyboard shortcuts

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