package main import ( "fmt" "os" p "path" "strings" ) func usage() { fmt.Printf("usage: %v path [suffix]\n", os.Args[0]) os.Exit(1) } func basename(path, suffix string) string { result := p.Base(path) if suffix == "" { return result } return strings.SplitN(result, suffix, 2)[0] } func main() { if len(os.Args) == 1 || len(os.Args) > 3 { usage() } path := os.Args[1] suffix := "" if len(os.Args) == 3 { suffix = os.Args[2] } fmt.Println(basename(path, suffix)) }