UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
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.
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.
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.
Man pages:
chmod, read, vi
UNIX Hints & Hacks |
||||||||||||||||||||||||||||||||
Chapter 8: Editors |
|
|||||||||||||||||||||||||||||||
|
© Copyright Macmillan USA. All rights reserved.