Script to generate templated PHP code I've created a script to create a module in our MVC framework. The structure of the module is like this (for this example, the module is called test):

test &gt;
    Test.php
    controllers &gt;
        IndexController.php
    models &gt;
        TestModel.php
    open &gt;
       css &gt;
       js &gt;
    views &gt;


Here's what I have for the script. If can have an optional flag of -o to allow the script to remove and override the folder is it already exists.

#!/bin/bash


OVERRIDE=false

while getopts ":o" opt; do
        case $opt in
                o ) OVERRIDE=true
        esac
done


# Check we're in the right directory.

if [ ${PWD##*/} != "modules" ]; then
        echo "Make sure you're in the modules directory"
        exit 1
fi


echo "Enter the module name you want:"

# Get the name, and format it into the formats we need.
read moduleName
lowercaseModuleName=${moduleName,,}
uppercaseFirstModuleName=${lowercaseModuleName^}



# Check if the directory exists already.
if [ -d $lowercaseModuleName ]
    then
        if [ "$OVERRIDE" = true ]; then
                echo "Directory already exists, overridding it because of the -o flag"
                rm -rf $lowercaseModuleName
        else

                echo "Directory '$lowercaseModuleName' already exists, please remove if and try again. To have it overridden please use the -o flag"
                exit 1;
        fi
fi

# Make dir.
echo "Adding module $lowercaseModuleName..."
mkdir $lowercaseModuleName
cd $lowercaseModuleName


# Make root class
echo "Adding Root class..."
cat &gt; $uppercaseFirstModuleName.php &lt;&lt; EOF
&lt;?php

class $uppercaseFirstModuleName extends Layer_Shared_Controller {

        public function preDispatch(){

        }
}
EOF




# Make controllers
echo "Adding IndexController..."
mkdir controllers
cd controllers

cat &gt; IndexController.php &lt;&lt; EOF
&lt;?php

class IndexController extends $uppercaseFirstModuleName {

        /**
         * Index action.
         */

        public function indexAction(){

        }
}
EOF



# Add model
echo "Adding model..."
cd ../
mkdir models
cd models

cat &gt; $uppercaseFirstModuleName"Model.php" &lt;&lt; EOF
&lt;?php

class ${uppercaseFirstModuleName}Model extends Layer_Model {

}
EOF


# Add open folder
echo "Adding open folder..."
cd ../
mkdir open
cd open
mkdir css js
cd ../


# Add view folder
echo "Adding view folder..."
mkdir views
cd ../

echo "Done! Module $uppercaseFirstModuleName created."


Is there anything bad/suboptimal, or that could be done easier?
just a few ideas from the top of my head.

I would define a variable with your start directory at the top of the script, so to that you can always refer to absolute paths in contrast to using cd ../ often. In case you ever change the structure of your script, this will ensure that everything keeps working.

MODULE_DIR=$(readlink -f $lowercaseModuleName)


Now the directory creation can be simplified:

# Add open folder
echo "Adding open folder..."
mkdir -p ${MODULE_DIR}/open/{css,js}/    

# Add views folder
echo "Adding view folder..."
mkdir ${MODULE_DIR}/views


As for the structure, I'd probaly create all the directories in one 'paragraph' and add the templates in a second step, just so that you one place where you can clearly see which directories are being created. But that might just be my personal tast.

In the template creation I'd use absolute paths here as well, using the new MODULE_DIR variable. Keeps you from having to navigate around a lot using cd which might cause confusion later on. 

Hope this helps!