shellwords

package module
v1.1.0 Latest Latest
Warning

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

Go to latest
Published: Apr 20, 2023 License: Apache-2.0 Imports: 4 Imported by: 8

README

shellwords

License Go Report Card codecov GoDoc

A Golang library to manipulate strings according to the word parsing rules of the UNIX Bourne shell.

Installation

go get github.com/Wing924/shellwords

Usage

import "github.com/Wing924/shellwords"
args, err := shellwords.Split("./foo --bar=baz")
// args should be ["./foo", "--bar=baz"]

args, err := shellwords.Split("./foo 'a b c'")
// args should be ["./foo", "a b c"]
line := shellwords.Join([]string{"abc", "d e f"})
// line should be `abc d\ e\ f`
line := shellwords.Escape("./foo 'a b c'")
// line should be `./foo\ \'a\ b\ c\'\"`

Thanks

This is based on ruby module: Shellwords

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Escape

func Escape(str string) string

Escape escapes a string so that it can be safely used in a Bourne shell command line. Note that a resulted string should be used unquoted and is not intended for use in double quotes nor in single quotes.

func Join

func Join(words []string) string

Join builds a command line string from an argument list by joining all elements escaped for Bourne shell and separated by a space.

func Split

func Split(line string) ([]string, error)

Split a string into an array of tokens in the same way the UNIX Bourne shell does.

Types

This section is empty.

Jump to

Keyboard shortcuts

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