• Linux
  • October 2018
    M T W T F S S
    « Sep   Nov »
    1234567
    891011121314
    15161718192021
    22232425262728
    293031  
  • Meta

  • Follow me on Twitter

  • Advertisements

Script to create scripts

I’d been playing around with sed in scripts to modify and insert licenses into scripts and source code and even set up a script to insert a basic header into existing scripts. Last night, the idea of writing a script to create the foundation of a script – the hash-bang and a basic header.

This morning I sat down and wrote the script. I started with checks for the arguments. I didn’t want a new script overwriting an existing one and I wanted to make sure that something was passed to give the new script a name.

Then I used sed to modify a header template, filling in information such as the name of the script, the author and the author’s email. I was able to get sed to append the modified header into the file like I did with my license script. I used the cat command to concatenate it. It works.

Once the script foundation is created, I delete the temporary header file and give the new script execute permissions. Then I give the user the option to open the script in nano for editing or displaying it using cat.

The output is as follows:

#!/bin/bash
#####################################################################
# Script Name :testscript.sh
# Description :
# Dependencies :
# Arguments :
# Author :Richard Romig
# Email :rick.romig@gmail.com
#####################################################################

Advertisements

3 Responses

  1. I changed the script to add the line “exit 0” after the hash-bang and then used sed to insert the temporary header file immediately after the hash-bang. That worked well enough.

    Then I used the script to create a script to insert a modified header into existing scripts.This scripts gives the option to open in nano to add other information to the header.

  2. This evening I wrote a similar script to create a new C source code file from a modified template that uses sed to fill in the program name, the copyright year, the programmer’s name and email, and the current date. This will save me the trouble of either copying the template file or cutting and pasting from the template.

  3. I added the #!/bin/bash to the bash header template and changed the first script to redirect the sed modified template to the new script in the same way as my script to create a C source code file from a template. I also added the date of the file creation.

Comments are closed.

%d bloggers like this: