Shell-ish text processing algorithm collection
- Splitter that supports quoted string.
- Escape/Unescape string for shell
$ go get github.com/shibukawa/shellfunc Parse(src string) []string
Split src string by space. If the chunk is quoted, the spaces between double-quotations are ignored.
import "github.com/shibukawa/shell"
func parse() {
opts := shell.Parse(`foo bar baz "hello world"`)
// opts[0] = "foo"
// opts[1] = "bar"
// opts[2] = "baz"
// opts[3] = "hello world"
}func Escape(src string) string
Escape src string.
If src string contains the following characters, it quotes the src and escape some characters:
"$@&'()^|[]{};*?<>\`\- Escape sequences:
\r\n\t - White space
func Unescape(quotedSrc string) string
It return unescaped string.
MIT