Skip to content
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

Basename introduces a line feed #175

Open
valrusu opened this issue May 12, 2023 · 1 comment
Open

Basename introduces a line feed #175

valrusu opened this issue May 12, 2023 · 1 comment

Comments

@valrusu
Copy link

valrusu commented May 12, 2023

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*

@bitfield
Copy link
Owner

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()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants