#!/usr/bin/env bash
DIR1=folderone
DIR2=foldertwo
function template() {
    if [[ ! -d $DIR ]]; 
        then
            echo "Creating $DIR folder."
            mkdir -p $DIR
        else
            echo "$DIR Folder exists"
    fi
}
echo "Select folder by number:"
echo "1) $DIR1"
echo "2) $DIR2"
read dirnumber
case $dirnumber in
    1) template | sed -e "s/\$DIR/$DIR1/g" ;;
    2) template | sed -e "s/\$DIR/$DIR2/g" ;;
    *) echo "Good bye!"
esac
case $1 in
    -c) createdir
    ;;  
    *) exit 1
    ;;
esac
I have template function and use it in case. I want reuse it and exchange it with $DIR1 or $DIR2 and run the code.
DIR1 and DIR2 are displayed correctly, but in case $dirnumber it doesn't.
Is there a way to do this?
Any help is appreciated. Thank you!
 
    