Last active
February 7, 2017 10:22
-
-
Save alwqx/ef538582f6001408321827c86d10c198 to your computer and use it in GitHub Desktop.
go text remove extra space of script output
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import( | |
"os/exec" | |
"os" | |
"fmt" | |
) | |
func main() { | |
devices := getDevices() | |
fmt.Println(devices) | |
fmt.Println(len(devices)) | |
} | |
func getDevices() []string { | |
ret, err := exec.Command("/sbin/smartctl", "--scan").Output() | |
if err != nil { | |
log.Println("Execute /sbin/smartctl --scan error: %v", err) | |
os.Exit(-1) | |
} | |
linest := strings.Split(string(ret), "\n") | |
lines := linest[:len(linest)-1] // remove last extra line with output of bash command | |
var devList = []string{} | |
for _, line := range lines { | |
device := strings.Fields(line)[0] | |
devList = append(devList, device) | |
} | |
return devList | |
} | |
/* | |
remove extra line | |
[/dev/sda] | |
1 | |
not remove extra line | |
[/dev/sda ] | |
2 | |
*/ |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment