dimanche 18 mars 2018

How to check if command has matched output

I have a BASH script that will create a bootable USB drive with GRUB.

The current problem is that the script will continue even if no USB drive is inserted. This will cause the user to continue without any safety measures especially if the user is new to command line.

I want a command that will check if the output is either sdb, sdc, sdd, sde or sdf. If the output matches either sdb, sdc, sdd, sde or sdf then the script will continue. If none of the output matches sdb, sdc, sdd, sde or sdf, then the script will exit. The current command below does not work. I didn't post all of the code because I think only this is important.

The command with a quote is the command that will check for the output

"if [[ $(lsblk | grep -w "sdb\|sdc\|sdd\|sde\|sdf") ]]; then
    echo "No USB drive found. Please insert one."
fi"

echo -e "--------------------------------" | lolcat
echo
lsblk | grep -w "sdb\|sdc\|sdd\|sde\|sdf" | lolcat
echo
echo -e "--------------------------------" | lolcat
echo

echo -e "Which pendrive listed above do you want to install MMI on?" | lolcat

echo

echo -e "Input example:" | lolcat
echo -e "(sdx) without brackets" | lolcat
read -p ":" INSTALLATION_DRIVE

echo

if [ -z "${INSTALLATION_DRIVE}" ]
then
    echo -e "Invalid input, quitting..."
    exit 1
fi

Sorry for the lolcat! Just want to make the script colourful!

Aucun commentaire:

Enregistrer un commentaire