BASH

Verify Required Command Line Tools Availability

A Bash script to check for the presence of essential command-line tools like `node` or `docker`, notifying users if any are missing to ensure proper development environment setup.

#!/bin/bash
# Checks if a list of required command-line tools are installed.
# Exits with an error if any required tool is missing.

REQUIRED_TOOLS=("node" "npm" "git" "docker") # Add or remove tools as needed

MISSING_TOOLS=()

echo "Checking for required command-line tools..."

for tool in "${REQUIRED_TOOLS[@]}"; do
    if ! command -v "$tool" &> /dev/null; then
        MISSING_TOOLS+=("$tool")
    fi
done

if [ ${#MISSING_TOOLS[@]} -gt 0 ]; then
    echo "--------------------------------------------------------"
    echo "ERROR: The following required tools are not installed or not in your PATH:"
    for missing_tool in "${MISSING_TOOLS[@]}"; do
        echo "  - $missing_tool"
    done
    echo "Please install them to proceed."
    echo "--------------------------------------------------------"
    exit 1
else
    echo "All required tools are installed: ${REQUIRED_TOOLS[*]}"
    exit 0
fi
How it works: This script helps ensure a consistent development or deployment environment by verifying that a predefined list of command-line tools is installed and accessible in the system's PATH. It iterates through the `REQUIRED_TOOLS` array, using `command -v` to check each one. If any tool is missing, the script collects them, prints a clear error message listing the missing tools, and then exits with a non-zero status, preventing further execution until the prerequisites are met. This is crucial for onboarding new developers or setting up CI/CD pipelines.

Need help integrating this into your project?

Our team of expert developers can help you build your custom application from scratch.

Hire DigitalCodeLabs