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

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