Documentation
¶
Overview ¶
Package which - locates executable files in the current path. A cross-platform implementation of the `which(1)` command.
This allows finding programs by searching the current `PATH` environment variable without needing to shell out to the operating system's `which` command.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func All ¶
All returns all instances of the executable program(s), instead of just the first one.
Example ¶
path := All("zsh") fmt.Printf("%v", path)
Output: [/usr/local/bin/zsh /bin/zsh]
Example (Multiples) ¶
When given multiple arguments, `All` will return all paths, sorted by argument order
path := All("zsh", "bash") fmt.Printf("%v", path)
Output: [/usr/local/bin/zsh /bin/zsh /bin/bash]
func Found ¶
Found returns true if all of the given executable program(s) are found, false if one or more are not found.
Example ¶
if Found("zsh") { fmt.Println("got it!") } if !Found("bogon") { fmt.Println("phew, no bogons") }
Output: got it! phew, no bogons
Example (Multiples) ¶
When given multiple arguments, `Found` will return all paths, sorted by argument order
if Found("zsh", "bash") { fmt.Println("a decent collection of shells") } if !Found("zsh", "bash", "ash") { fmt.Println("just missing the ashes...") }
Output: a decent collection of shells just missing the ashes...
func Which ¶
Which locates executable program(s) in the user's path. If more than one occurrence is found, the first will be returned. Unlike the UNIX which(1) command, even if multiple programs are given as input, only the first-found will be returned. If none of the programs are found, the empty string is returned.
Example ¶
path := Which("sh") fmt.Printf("Found sh at: %s", path)
Output: Found sh at: /bin/sh
Example (Multiples) ¶
When given multiple arguments, `Which` will return the path for the first found
path := Which("bogus", "sh") fmt.Printf("First found was: %s", path)
Output: First found was: /bin/sh
Types ¶
This section is empty.