I'm confused about glob usage on Golang, I'm probably missing some environment variable. I don't know if I'm doing it right.
This code works perfectly fine when ran on my IDE (Intellij IDEA), but when this is ran on the OS via go run
it doesn't work. I can't figure out what is the difference.
package main
import (
"path/filepath"
"fmt"
"os"
)
func main() {
file := os.Args[1]
matches, err := filepath.Glob(file)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
fmt.Println(fmt.Sprintf("Number of matches:%d", len(matches)))
fmt.Println(matches)
}
Running on OS
go run globtest.go /Users/bernardovale/glotest/*.bkp
Number of matches:1
[/Users/bernardovale/glotest/test1.bkp]
ls -l /Users/bernardovale/glotest/*.bkp
-rw-r--r-- 1 bernardovale staff 0 May 27 12:06 /Users/bernardovale/glotest/test1.bkp
-rw-r--r-- 1 bernardovale staff 0 May 27 12:06 /Users/bernardovale/glotest/test2.bkp
-rw-r--r-- 1 bernardovale staff 0 May 27 12:06 /Users/bernardovale/glotest/test3.bkp
Running on IntelliJ IDEA