I have a string that is separated by spaces, in this example, its a command: ls -al.
Go has a method exec.Command that needs to accept this command as multiple arguments, I call it like so: exec.Command("ls", "-al")
Is there a way to take a arbitrary string, split it by spaces, and pass all of its values as arguments to the method?
I recently discovered a nice package that handles splitting strings exactly as the shell would, including handling quotes, etc: https://github.com/kballard/go-shellquote
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With