Create New C++ Class I'm currently developing a new version of ExpressGenGen Using TDD. While I'm rewriting the new version of my Code Generator Generator.
I'm using its old version to generate code to be used by the new version. 
This is how I'm creating new classes: when a new class is created,
it will generate a .cpp and .h file and then add them to CMakeLists.txt,
and also TestHelper.h is updated with new headers. 

What I want reviewed are the bash scripts. (You are also welcome to review the ExpressGenGen templates)

Bash Scripts

gen

#!/bin/bash

cd ..
cat Samples/template_bash_CMakeLists.txt | xgengen bash | bash - &gt; CMakeLists.txt
cat Samples/template_bash_TestHelper.txt | xgengen bash | bash - &gt; Tests/TestHelper.h


new_class

#!/bin/bash

echo 'Create New Class'
echo '--------------------------'
echo 'Type Class Name : '
read _class
# convert Upper Camel case to header guard, ex: NewClass -&gt; _NEW_CLASS_H_
_guard=`echo $_class | sed -e 's/\([A-Z]\)/_\1/g' | awk '{printf toupper($0)} END{printf "_H_";}'`
# export the variables so they are visible to the child shell
export guard=$_guard
export class=$_class
cat template_bash_CPP.txt | xgengen bash | bash - &gt; "../Src/$class.cpp"
cat template_bash_H.txt | xgengen bash | bash - &gt; "../Src/$class.h"
./gen


Templates

template_bash_CMakeLists.txt

project(ExpressGenGen)

cmake_minimum_required(VERSION 2.6)
include_directories($ENV{BOOST_ROOT} $ENV{LUA_ROOT} $ENV{GMOCK_HOME}/include $ENV{GMOCK_HOME}/gtest/include .)
link_directories($ENV{LUA_ROOT} $ENV{BOOST_ROOT}/stage/lib $ENV{GMOCK_HOME}/build $ENV{GMOCK_HOME}/build/gtest) 
set(CMAKE_CXX_FLAGS "${CMAXE_CXX_FLAGS} -Wall -Wpedantic -std=gnu++11")

set(sources 
$$$find . -name '*.cpp' | sed 's/\.\//  /'
    $$$find . -name '*.h' | sed 's/\.\//  /'
  WindowsRsrc/WindowsRes.rc)
add_executable(xgengen ${sources})
target_link_libraries(xgengen lua)
target_link_libraries(xgengen boost_program_options)
target_link_libraries(xgengen pthread)
target_link_libraries(xgengen gmock)
target_link_libraries(xgengen gtest)


template_bash_CPP.txt

//--------------------------------------------
// Definition
#include "{$$$class$$}.h"
//--------------------------------------------
// Uses
//
//--------------------------------------------

{$$$class$$}::{$$$class$$}()
{

}

//--------------------------------------------


template_bash_H.txt

#ifndef {$$$guard$$}
#define {$$$guard$$}

//--------------------------------------------
// Has
//
//--------------------------------------------
// Inherits
//
//--------------------------------------------
// Uses
//
//--------------------------------------------

class {$$$class$$} {
public:
    {$$$class$$}();
    virtual ~{$$$class$$}() {}

private:
};

//-------------------------------------------

#endif // {$$$guard$$}


template_bash_TestHelper.txt

//--------------------------------------------
// TestHelper
//
// This header is basically an include all type helper for Test*.cpp files
// therefore greatly reducing duplication
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wall"
#pragma GCC diagnostic ignored "-Wpedantic"
#pragma GCC diagnostic ignored "-Wunused-local-typedefs"
#include &lt;gmock/gmock.h&gt;
#pragma GCC diagnostic pop

#include &lt;iostream&gt;
#include &lt;istream&gt;
#include &lt;sstream&gt;
#include &lt;memory&gt;
// AutoGenerated
$$$find Src -name "*.h" | sed -e 's/\(.*\)/#include \"\.\.\/\1\"/g'
// End AutoGenerated
//--------------------------------------------
Use input redirection instead of cat | ...

Instead of cat somefile | somecommand, you should use input redirection, for example:

xgengen bash &lt; Samples/template_bash_CMakeLists.txt | bash - &gt; CMakeLists.txt


The advantage of this is that you're running one fewer process (no more cat).

Use modern style command substitution $(...)

Don't use old style `...` command substitution.
Use the modern and better $(...) style.

Simplify sed + awk pipelines when possible

This looks very complicated, and it's suspicious to have both sed and awk in the same pipeline:

echo $_class | sed -e 's/\([A-Z]\)/_\1/g' | awk '{printf toupper($0)} END{printf "_H_";}'


You can simplify using a single awk command:

echo $_class | awk '{gsub("[A-Z]", "_\&amp;"); printf toupper($0) "_H_"}'


Use here-strings instead of echo | ...

Similar to using input redirection instead of cat | ...,
in Bash it's better to replace echo | ... with here-strings using &lt;&lt;&lt;,
rewriting the above example as:

awk '{gsub("[A-Z]", "_\&amp;"); printf toupper($0) "_H_"}' &lt;&lt;&lt; $_class


Use alternative regex pattern separator to improve readability

When a regular expression pattern contains /,
using such patterns with the s/// operator becomes tedious and hard to read,
because of the escapes.
To improve readability, it's often good to use an alternative pattern separator.
So for example instead of this:

sed 's/\.\//  /'


You can do this instead to avoid escaping /:

sed 's|\./|  |'


The benefit is more obvious when you have multiple / in the pattern.
In this example the difference might be negligible.

Simplify regex

The s/// here can be simplified:

sed -e 's/\(.*\)/#include \"\.\.\/\1\"/g'


To this:

sed -e 's/.*/#include "..\/&amp;"/'


That is:


No need to capture .* in \(...\), you can access the matched string directly with &amp;
No need to escape . in replacement, as it has no special meaning there
No need to escape " within single-quoted strings in Bash
Since the pattern matches the entire line, no need for the g flag