Skip to content

shibukawa/shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Shell Style Text Processing

Shell-ish text processing algorithm collection

  • Splitter that supports quoted string.
  • Escape/Unescape string for shell

Install

$ go get github.com/shibukawa/shell

Reference

Split

func 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"
}

Escape

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

Unescape

func Unescape(quotedSrc string) string

It return unescaped string.

License

MIT

About

Shell-ish string splitter. It supports quoted string with space.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages