github.com/bingoohuang/gg@v0.0.0-20240325092523-45da7dee9335/pkg/shellwords/README.md (about) 1 # shellwords 2 3 [](https://codecov.io/gh/bingoohuang/shellwords) 4 [](https://travis-ci.org/bingoohuang/shellwords) 5 [](http://godoc.org/github.com/bingoohuang/shellwords) 6 7 Parse line as shell words. 8 9 ## Usage 10 11 ```go 12 args, err := shellwords.Parse("./foo --bar=baz") 13 // args should be ["./foo", "--bar=baz"] 14 ``` 15 16 ```go 17 os.Setenv("FOO", "bar") 18 p := shellwords.NewParser() 19 p.ParseEnv = true 20 args, err := p.Parse("./foo $FOO") 21 // args should be ["./foo", "bar"] 22 ``` 23 24 ```go 25 p := shellwords.NewParser() 26 p.ParseBacktick = true 27 args, err := p.Parse("./foo `echo $SHELL`") 28 // args should be ["./foo", "/bin/bash"] 29 ``` 30 31 ```go 32 shellwords.ParseBacktick = true 33 p := shellwords.NewParser() 34 args, err := p.Parse("./foo `echo $SHELL`") 35 // args should be ["./foo", "/bin/bash"] 36 ``` 37 38 # Thanks 39 40 This is based on cpan module [Parse::CommandLine](https://metacpan.org/pod/Parse::CommandLine). 41 42 # License 43 44 under the MIT License: http://mattn.mit-license.org/2017 45 46 # Author 47 48 Yasuhiro Matsumoto (a.k.a mattn)