Skip to content

Add command -v check before use commands #3

Description

@FailProger

Problem

Use wget or debootstrap without check command available.

Solution

Add function assert_commands to lib for check commands available after installation.

Example:

assert_commands() {
    local missing=()
    for cmd in "$@"; do
        if ! command -v "$cmd" &>/dev/null; then
            missing+=("$cmd")
        fi
    done
    if [[ ${#missing[@]} -gt 0 ]]; then
        echo "Error: commands not found: ${missing[*]}. Exit..."
        exit 1
    fi
}

Use example:

apt update &&
> apt install -y wget debootstrap &&
> assert_commands wget debootstrap

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions