Well, with this onset of pandemic, all of us have been forced indoors but The show must go on
right? So, here we are attending classes from our bed or maybe working from home. If you are someone like me who always tries to find various ways on how to minimise efforts, this article is for you.
To all the student audience out there, do you guys get assignments daily? Well, certainly I do. I am not exactly sure how you guys submit your assignment, but we generally have to make a pdf. If you are doing engineering, then in your entire curriculum, you definitely have written codes and in this pandemic, you are expected to write all the code in a single pdf and submit them. Imagine first coding 10-20 problems and then copy pasting each one of them to a docx file and then exporting them to PDF. While this might not sound much but doing it everyday for 3-4 times will surely make you go crazy.
Well, what is the use of knowing how to code if you can’t ease your own life? So, here I have come up with a simple solution to help myself out. My approach is simple, create a bash script to do the boring task.
So, let’s quickly walk through all the things that we need to implement in the script.
-
First, we would want our script to be as robust as possible, so we would typically want to take the directory and the output file name as input. Also, we want to extend it to be able to work with any code file, so we would also want to pass in the extension.
-
Next, we need a way to be able to loop through all the extension files in the directory.
-
Once we have the looping in place, we would want to write the codes to a temporary file, keeping in mind that each code in pdf should start with the code number.
-
After all of this is done, we would want to convert the temporary file to pdf and then delete the temporary file.
With all of these points in mind, here is the script which does all the magic.
Well I hope this was helpful for all the lazy folks out there. Stay safe, stay indoors and be lazy.