-
-
Notifications
You must be signed in to change notification settings - Fork 315
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
String method return a new line when followed by Exec #161
Comments
If you run the command |
Right. echo \
"deb [arch=$(dpkg --print-architecture) signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian $(lsb_release -cs) stable" | sudo tee /etc/apt/sources.list.d/docker.list > /dev/null And how I'm doing with arch, err := script.Exec("dpkg --print-architecture").String()
if err != nil {
log.Fatal(err)
}
versionName, err := script.Exec("lsb_release -cs").String()
if err != nil {
log.Fatal(err)
}
_, err := exec.Echo(fmt.Sprintf("deb [arch=%s signed-by=/etc/apt/keyrings/docker.gpg] https://download.docker.com/linux/debian %s stable", arch, versionName)).Exec("sudo tee /etc/apt/sources.list.d/docker.list").String()
if err != nil {
log.Fatal(err)
} Because |
If you're looking to add a newline -- use printf instead of echo:
If you're looking to remove the newline from the end of the string you can do it like this:
That will remove all whitespace from both sides of the string. |
Calling
String
followed byExec
returns a string ending with a new line (i.e.\n
).Example:
It prints:
"hello\n"
Is this intended or the
\n
shouldn't be there?If I'm not mistaken the issue is that
os/exec.Command
returns it. Execute this exampleAnd you see that it prints:
"hello\n"
The text was updated successfully, but these errors were encountered: