UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

8.10 Edit, Run, and Edit Again

8.10.1 Description

8.10.1 Description

This script should help you write scripts more quickly. It lets you edit a file, run the file, and edit it again in an endless loop.

Flavors: AT&T, BSD

Shells: sh, ksh

Syntax:

ere filename

The Edit Run Edit ( ere) script was written to help save time when you are developing a script. There are a couple ways to develop a script when you write it. One is to have two windows open--the editor in one and the script, constantly running, in the other. The other is to load, edit, and save the script; quit; run the script; and load the script again to fix any errors. Both methods can take up time and space on your desktop. The ere is short, quick, dirty, and to the point.

rocket 41% vi ere
#! /bin/sh file="$1" if [ -z "$file" ]; then exit; fi while [ 1 ]; do vi $file chmod 755 $file $file echo -n "Hit [return], or [CTRL-C] to stop"; read x done

Line 1: Define the shell.

Line 2: Read in the filename passed.

Line 3: Check whether there is a filename entered.

Line 4: Exit if there is no filename entered.

Line 6: Begin an endless loop.

Line 7: Load the file to be worked on.

Line 8: Make the file executable.

Line 9: Execute the file.

Line 10: Continue or stop the process.

When you pass a filename to the ere script it immediately brings the file into a vi session for editing. When a write and quit is done, ere then changes the permissions on the file to 755 and tries to execute the file as a script. If the program exits gracefully or with a problem, it asks whether you would like to continue editing or exit. Pressing the Enter key takes you back to the editor and a Ctrl-c exits the ere script at this point. You can stay in ere as long as it takes to get the script working.

Reason

The repetitious routine of editing, running, and editing scripts when they are created needs to be made easier. Having a script that handles this for you speeds up the development process for your scripts.

Real World Experience

I simply got tired of all the loading and exiting I was doing whenever I built scripts. Since writing this script, I have saved time and keystrokes by having the process completely automated for me. The UGU Web site is over 1200 lines of Perl. When I wrote the code for the site, I didn't get it right the first time, or the second, or the third. This script saved valuable and much-needed time over the hours of developing UGU.

Other Resources

Man pages:

chmod, read, vi

UNIX Hints & Hacks

ContentsIndex

Chapter 8: Editors

 

Previous ChapterNext Chapter

Sections in this Chapter:

   

8.1 The Anatomy of ed & vi

 

8.5 Abbreviating vi Commands

 

 

8.2 The Six Steps to ed

 

8.6 Creating Macros

 

8.10 Edit, Run, and Edit Again

 

8.3 Six Simple Steps to vi

 

8.7 Search and Replace

 

8.11 Reading STDOUT into vi

 

8.4 Configuring vi Parameters

 

8.8 Other Places to Use vi

 

8.12 Using vi when tmp Is Full

 

 

© Copyright Macmillan USA. All rights reserved.