mercredi 21 février 2018

A better way to write an if statement in Bash

Having several scripts which follow the below pattern, and I'm curious if you folks have suggestions on reducing the number of lines or if you're doing this more streamlined?

What I don't like necessarily is that I'm using too many $? checks, and end up with nested if loops - not sure if that is a bad thing though.

Code I'm looking to optimize but still keep the functionality is like this:

    wget -V > /dev/null 2>&1
    if [ $? -ne 0 ]; then
        apt install wget
        if [ $? -ne 0 ]; then
            "failed to install wget" 
        fi
    fi

Aucun commentaire:

Enregistrer un commentaire