Q:

Want to write a bash script to automate creating program files

I want to write a bash script that can:

create a file with a specific name entered by user.  If user doesnt enter a name, it should provide a default name but also check if that name is present. 
Allow some more variables to be entered by user that can be used to populate that program file, including filling up the comments section (for things like author_name)

I don't have much experience in writing bash scripts so please provide small code examples.  Thanks a lot! 
PS: I guess this is pretty much like the npm init script that creates the package.json file.  I cant find that script, so if it's open source please provide a link if you have it.  
I have written this uptil now: 
Skeleton:
/*
 * URL : 
 * Author: John M.
 * Timestamp: 
 */

#include <iostream>
#include <algorithm>
#include <vector> 

using namespace std;

int main(int argc, char* argv[]) {
    // code
}

Skeleton.sh
#! /bin/bash

created=0
while [ $created==0 ]; do
    read -p "Enter name of new C++ program file (code.cpp)" name
    case $name in 
        * ) name="code.cpp";;
    esac
    if [ -e $name ]; then
        echo "File name $name already exists!" 
        echo "Please provide a different filename"
    else 
        echo >> $name
        created=1
    fi
done

cat Skeleton > $name        # there's an error in this line, dont know what is wrong here

This isn't a homework.  I am just trying to automate creating a new file.  Its not going to be just a C++ file creation (in case someone tells me to just use an ide).  
I would like to be able to fill in the timestamp by generating it through the script and also be able to fill in the URL using script.  If someone can provide help, that'd be appreciated.  Thanks
EDIT:
I added these 2 lines in the accepted answer:
  local curr_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
  subl "$curr_dir/$prog_name"

Right now I am using sublime text, so this works out.  But if I am on a computer that doesn't have sublime text installed, can I make such changes to script that if it isn't, it opens gedit or something else instead of just giving an error? 

A:

Examine the script below.  I recommend using cat with heredoc structure to write out large chunks of text with substituting variables.  Also, break down the code into functions - it will be far more readable and easier to debug. 
Some of the technical aspectes have already been mentioned here.  I'm using heredoc structure with cat to write out header and body.  tee command is used to write out the info to both stdout and to file.  That way you can see on command-line that if anything went wrong, you don't have to open the file - just delete it and make new one.  As for existing filename, that's simply a while loop that keeps bugging the user until they actually enter the name what doesn't exist.  
Script
#! /bin/bash

make_header()
{
    timestamp=$(date)
    echo "/*"
    cat << EOF
 * URL:
 * Author: $1
 * Timestamp: $timestamp
EOF
echo " */"
}

make_body()
{
    cat << EOF

#include <iostream>
#include <algorithm>
#include <vector> 

using namespace std;

int main(int argc, char* argv[]) {
    // code
}

EOF
}

check_name_exists()
{

    while [ -e "$prog_name" ];
    do
        echo ">>> $prog_name: file exists, please choose different name:"
        read prog_name
    done
}

main()
{
    local prog_name=""
    local author
    local default_name="my_prog.cpp"

    echo "Enter author name:"
    read author
    echo "Enter program name:"
    read prog_name
    if [ "x$prog_name" == "x"  ];then
        prog_name="$default_name"
    fi

    check_name_exists

    header=$(make_header "$author")
    body=$(make_body)
    echo "$header" "$body" | tee "$prog_name"

}
main

Demo:
$ ./skeleton.sh                                                                                                                  
Enter author name:
John Doe
Enter program name:
code.cpp
>>> code.cpp: file exists, please choose different name:
code.cpp
>>> code.cpp: file exists, please choose different name:
code1.cpp
/*
 * URL:
 * Author: John Doe
 * Timestamp: 2016年 11月 06日 星期日 12:42:01 MST
 */ 
#include <iostream>
#include <algorithm>
#include <vector> 

using namespace std;

int main(int argc, char* argv[]) {
    // code
}

