• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..03-May-2022-

.github/H17-Jan-2021-3734

_example/H17-Jan-2021-4537

.travis.ymlH A D17-Jan-2021191 1713

LICENSEH A D17-Jan-20211.1 KiB2217

README.mdH A D17-Jan-20211.4 KiB5641

go.modH A D17-Jan-202147 42

go.test.shH A D17-Jan-2021267 139

shellwords.goH A D17-Jan-20215.8 KiB318290

shellwords_test.goH A D17-Jan-202110.3 KiB457411

util_posix.goH A D17-Jan-2021505 3025

util_windows.goH A D17-Jan-2021502 3025

README.md

1# go-shellwords
2
3[![codecov](https://codecov.io/gh/mattn/go-shellwords/branch/master/graph/badge.svg)](https://codecov.io/gh/mattn/go-shellwords)
4[![Build Status](https://travis-ci.org/mattn/go-shellwords.svg?branch=master)](https://travis-ci.org/mattn/go-shellwords)
5[![PkgGoDev](https://pkg.go.dev/badge/github.com/mattn/go-shellwords)](https://pkg.go.dev/github.com/mattn/go-shellwords)
6[![ci](https://github.com/mattn/go-shellwords/ci/badge.svg)](https://github.com/mattn/go-shellwords/actions)
7
8Parse line as shell words.
9
10## Usage
11
12```go
13args, err := shellwords.Parse("./foo --bar=baz")
14// args should be ["./foo", "--bar=baz"]
15```
16
17```go
18envs, args, err := shellwords.ParseWithEnvs("FOO=foo BAR=baz ./foo --bar=baz")
19// envs should be ["FOO=foo", "BAR=baz"]
20// args should be ["./foo", "--bar=baz"]
21```
22
23```go
24os.Setenv("FOO", "bar")
25p := shellwords.NewParser()
26p.ParseEnv = true
27args, err := p.Parse("./foo $FOO")
28// args should be ["./foo", "bar"]
29```
30
31```go
32p := shellwords.NewParser()
33p.ParseBacktick = true
34args, err := p.Parse("./foo `echo $SHELL`")
35// args should be ["./foo", "/bin/bash"]
36```
37
38```go
39shellwords.ParseBacktick = true
40p := shellwords.NewParser()
41args, err := p.Parse("./foo `echo $SHELL`")
42// args should be ["./foo", "/bin/bash"]
43```
44
45# Thanks
46
47This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse::CommandLine).
48
49# License
50
51under the MIT License: http://mattn.mit-license.org/2017
52
53# Author
54
55Yasuhiro Matsumoto (a.k.a mattn)
56