Check Presence of CLI Tools Using 'has' Script on Raspberry Pi

Check Presence of CLI Tools Using 'has' Script on Raspberry Pi

The PATH is an environment variable that contains a colon-delimited list of directories that tells where to search for executable files. The has is a Bash script that allows to check whether a command line tools exists in one of the directories in the PATH and outputs their installed versions.

This tutorial explains how to install and use has on Raspberry Pi.

Connect to Raspberry Pi via SSH and download the has script from GitHub repository to the /usr/local/bin directory. Then add execute permission to the script.

sudo wget -O /usr/local/bin/has https://raw.githubusercontent.com/kdabir/has/master/has
sudo chmod a+x /usr/local/bin/has

The has can be used for all users because it is available as a system-wide command. Check version by simple executing:

has

Now provide a list of command line tools you want to check as arguments to the has:

has git php java python

The has outputs whether a given tools exists alongside with versions.

✓ git 2.20.1
✗ php
✗ java
✓ python 2.7.16

The has can return message that says command not understood:

has traceroute mkdir
✗ traceroute not understood
✗ mkdir not understood

This means that given command is not whitelisted by has. In such case, use HAS_ALLOW_UNSAFE=y as follows:

HAS_ALLOW_UNSAFE=y has traceroute mkdir
✓ traceroute 2.1.0
✓ mkdir 8.30

If has script is no longer needed and decided to remove it, just execute the following command:

sudo rm -rf /usr/local/bin/has

Leave a Comment

Cancel reply

Your email address will not be published.