New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

github.com/hairyhenderson/go-which

Package Overview
Dependencies
Alerts
File Explorer
Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

github.com/hairyhenderson/go-which

  • v0.2.0
  • Source
  • Go
  • Socket score

Version published
Created
Source

go-which

Build Status hairyhenderson/go-which on DockerHub GoDoc

A cross-platform Go implementation of the which(1) command, usable both as a CLI and library.

Usage of which:
  -a    List all instances of executables found (instead of just the first).
  -s    No output, just return 0 if all executables are found, or 1 if some were not found.
  -v    Print the version

Unlike the UNIX which(1) command, even if multiple programs are given as input, only the first one found will be returned.

CLI Usage

Chances are you don't really need this, since most UNIX-like OSes come with the more established (and significantly smaller) C implementation of which(1), either as a standalone binary, or as a shell builtin.

But if there's some reason this may be useful to you, you can use this just like the normal which(1):

$ which zsh
/usr/local/bin/zsh
$ which -a zsh
/usr/local/bin/zsh
/bin/zsh
$ which zsh bash sh
/usr/local/bin/zsh
$ which -a zsh bash sh
/usr/local/bin/zsh
/bin/zsh
/bin/bash
/bin/sh
$ if (which -s zsh bash); then
> echo 'I have zsh and bash installed';
> fi
I have zsh and bash installed
$ if (which -s zsh bash ash); then echo 'yup'
> else
> echo "I'm missing one of them...";
> fi
I'm missing one of them...

Go package usage

If you're writing a program in the Go language, it can be useful to not have to shell out to which(1) to locate a binary.

The simplest usage is:

package main

import (
  "fmt"
  "github.com/hairyhenderson/go-which"
)

func main() {
  zshPath := which.Which("zsh")

  fmt.Printf("zsh found at %s", zshPath)
}

See the godocs for more information.

License

The MIT License

Copyright (c) 2018-2020 Dave Henderson

FAQs

Package last updated on 03 Aug 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc