Skip to content

larschri/go-cmd2shell

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Go cmd2shell

Convert exec.Cmd to a string that can be used as a shell command.

Environment, workdir, path and arguments are passed as parameters to the env command. The workdir is specified with the -L option which is available in GNU/Linux, but not POSIX. The strings in exec.Cmd.Env should be in KEY=VALUE format, otherwise an equal sign will be appended.

Shell quoting is handled by go-shellquote.

Install

go get github.com/larschri/go-cmd2shell

Example

c := exec.Command("echo", "Hello, world")
fmt.Println(cmd2shell.OneLiner(c))

This prints

env -i -C /current/work/dir /bin/echo 'Hello, world'

About

Convert exec.Cmd to a shell command

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages