buildkite/shellwords

Name: shellwords

Owner: Buildkite

Description: Splits command strings according to POSIX/Batch semantics

Created: 2018-03-15 05:22:22.0

Updated: 2018-03-23 10:41:53.0

Pushed: 2018-03-16 00:15:29.0

Homepage:

Size: 13

Language: Go

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

Shellwords

A golang library for splitting command-line strings into words like a Posix or Windows shell would.

Installation
et -u github.com/buildkite/shellwords
Usage
age main

rt (
ithub.com/buildkite/shellwords"
mt"


 main() {
rds := shellwords.Split(`/usr/bin/bash -e -c "llamas are the \"best\" && echo 'alpacas'"`)
r _, word := range words {
fmt.Println(word)



utputs:
usr/bin/bash
e
c
lamas are the "best" && echo 'alpacas'
Alternatives

Previously we were using https://github.com/mattn/go-shellwords, but it lacked support for Windows quoting and escaping conventions, specifically backslashed paths. It also supports things like env expansion and command execution, which made me very nervous, so I decided to write a simpler lexer that just addressed the splitting problem.

Other alternatives are https://github.com/flynn-archive/go-shlex and https://github.com/kballard/go-shellquote, of which the latter is probably closest in spirit to this library.

License

Licensed under MIT license, in LICENSE.


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.