Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Exec to handle quotes #42

Merged
merged 2 commits into from
Mar 28, 2020
Merged

Fix Exec to handle quotes #42

merged 2 commits into from
Mar 28, 2020

Conversation

bitfield
Copy link
Owner

Issue #32 highlighted a problem with the simple approach (strings.Fields) to splitting a command string into a suitable slice of strings for exec.Command. A program like this:

p := script.Exec("bash -c 'docker ps'")

didn't work as expected, because the actual slice of strings passed to the command was:

{"bash", "-c", "'docker", "ps'"}

which causes the shell to choke. We need a slightly smarter approach which takes into account quoted strings, and doesn't split them:

{"bash", "-c", "docker ps"}

The creachadair/shell library provides a facility (Split) to do exactly this. Thanks to @shumin1027 for the original report, @posener for input, and @jrswab for an initial draft PR on this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant