mercredi 24 mai 2017

How do I combine an "if" and a "while loop" statement together?

New to shell scripting and I want to test to see if the variables I created are valid directories and if not send the user into a while loop to enter the directory and only allow exit when a valid directory is entered.

So far this is what my script looks like:

~/bin/bash
source_dir="$1"
dest_dir="$2"

mkdir /#HOME/$source_dir
mkdir /#HOME$dest_dir


if [ -d  "$source_dir" ]
then
        echo "$source_dir is a valid directory"
fi

while [[ ! -d "$source_dir" ]]
do
        echo "Please enter a valid directory"
        read source_dir
done

Is there any way to combine these into a single statement?

Aucun commentaire:

Enregistrer un commentaire