Standard library / os/exec
os/exec.LookPath()
Searches PATH for an executable when the name contains no separator. Relative PATH results can return ErrDot; do not bypass that safety check blindly. Example intended for Linux/AMD64 with Go 1.23.2 in a disposable working directory; other platforms may differ. Expected stdout: 'true\n'.
Formal Syntax & Structure
go syntaxgo
func LookPath(file string) (string, error)Parameters & Attributes
| Name | Type | Description |
|---|---|---|
| file | string | Input to os/exec.LookPath(); see the operation contract. |
Return Value
(string, error)
Searches PATH for an executable when the name contains no separator.
Working Example
Example Snippetgo
package main
import ( "fmt" "os" "os/exec")
func must(e error) { if e != nil { panic(e) }}func main() { p, e := os.Executable(); must(e); q, e := exec.LookPath(p); must(e); fmt.Println(q == p) }