script
script copied to clipboard
Basename introduces a line feed
Hi
It seems Basename introduces a line feed in the generated path, hope I'm not doing anything wrong:
package main
import (
"fmt"
"os"
"path/filepath"
"github.com/bitfield/script"
)
func main() {
myname1, err := script.Echo(os.Args[0]).Basename().String()
if err != nil {
fmt.Println(err)
}
myname2 := filepath.Base(os.Args[0])
fmt.Printf("*%s*\n", myname1)
fmt.Printf("*%s*\n", myname2)
}
Results:
*main3.exe
*
*main3.exe*
That's right, @valrusu. It makes more sense when you think about a pipeline that contains multiple paths, one per line (which is the typical use case for script
).
For example:
script.FindFiles(".").Basename().Stdout()