We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 9cffd67 commit b1b26d6Copy full SHA for b1b26d6
9-filesystem-basic/which/go.mod
@@ -0,0 +1,3 @@
1
+module github.com/kyu08/go-system-programming/which
2
+
3
+go 1.22.3
9-filesystem-basic/which/main.go
@@ -0,0 +1,24 @@
+package main
+import (
4
+ "fmt"
5
+ "os"
6
+ "path/filepath"
7
+)
8
9
+func main() {
10
+ if len(os.Args) != 2 {
11
+ fmt.Printf("%s [exec path]\n", os.Args[0])
12
+ os.Exit(1)
13
+ }
14
15
+ for _, path := range filepath.SplitList(os.Getenv("PATH")) {
16
+ execpath := filepath.Join(path, os.Args[1])
17
+ _, err := os.Stat(execpath)
18
+ if !os.IsNotExist(err) {
19
+ fmt.Println(execpath)
20
+ return
21
22
23
24
+}
0 commit comments