Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
Write a template main.c file via shell script to make it easier for yourself later.
The issue here isn't writing the file though, I can do that with echo statements.
What I'd like to see is how to do this in a less redundant way? Note down in the attempts at solution, the amount of echos and >> main$ext is completely unnecessary.
So I'd like to see an alternative, more "efficient for the programmer", way of doing it.
Is there any way to work with a block of text within the shell script?
Edit: I'd also like to avoid all one echo statement with a bunch of "\n" characters, that would ALSO be redundant in my opinion.
-
Relevant commands, code, scripts, algorithms:
ext=".c"
proj="proj"
the echo statement
and >> the append redirection operator -
The attempts at a solution (include all code and scripts):
#! /bin/bash
# main.c
ext=".c"
read proj
echo "//$auth" > main$ext
echo "//main.$ext" >> main$ext
echo "//$proj main file" >> main$ext
echo "" >> main$ext
echo "#include <iostream>" >> main$ext
echo "#include <cstdlib>" >> main$ext
echo "" >> main$ext
echo "#include \".h\"" >> main$ext
echo "" >> main$ext
echo "" >> main$ext
The finished product looks akin to
//$auth
//main.c
//$proj main file/implementation
#include <iostream>
#include <cstdlib>
#include ".h"
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
University of California Davis, Davis, CA, USA, Sean Davis, ECS40
(This is extra work outside of class though so it really has nothing to do with school. I just like shell scripting lately)
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).