Categorygithub.com/anmitsu/go-shlex
modulepackage
0.0.0-20200514113438-38f4b401e2be
Repository: https://github.com/anmitsu/go-shlex.git
Documentation: pkg.go.dev

# README

go-shlex

go-shlex is a library to make a lexical analyzer like Unix shell for Go.

Install

go get -u "github.com/anmitsu/go-shlex"

Usage

package main

import (
    "fmt"
    "log"

    "github.com/anmitsu/go-shlex"
)

func main() {
    cmd := `cp -Rdp "file name" 'file name2' dir\ name`
    words, err := shlex.Split(cmd, true)
    if err != nil {
        log.Fatal(err)
    }

    for _, w := range words {
        fmt.Println(w)
    }
}

output

cp
-Rdp
file name
file name2
dir name

Documentation

http://godoc.org/github.com/anmitsu/go-shlex

# Functions

NewLexer creates a new Lexer reading from io.Reader.
NewLexerString creates a new Lexer reading from a string.
Split splits a string according to posix or non-posix rules.

# Variables

No description provided by the author
No description provided by the author

# Structs

DefaultTokenizer implements a simple tokenizer like Unix shell.
Lexer represents a lexical analyzer.

# Interfaces

Tokenizer is the interface that classifies a token according to words, whitespaces, quotations, escapes and escaped quotations.