Getting a Head Start on Scripts with history


Getting a Head Start on Scripts with history

If you find yourself performing a particular process over and over again, consider making that process into a script. An easy way to create a script is to work from the session history, as shown in Figure 10.3. Basically, all you have to do is complete the procedure one time, and then use the session history to help build the script for you.

Figure 10.3. You can enter a series of commands, and then use the code provided with history to help create a shell script.


To Get a Head Start on Your Script with history:

1.

Go through the process that you want to include in the script.

We'll wait.

2.

Keep a rough count of the commands you issue.

Don't worry about the exact number of commands you use, but have an idea as to whether it's 3, 30, or 300 commands.

3.

history 20 > standyou

When you've finished the process, type history followed by the approximate number of commands for your script. When estimating the number of commands, err on the high side, as it's easier to delete extra commands than to add in missing ones. Then, redirect the output to the desired filename, and see your in-the-making script stand before you.

4.

vi standyou

Use the editor of your choice to edit your script file, deleting the initial line numbers and spaces and generally whipping that script into shape. See the section Creating a Shell Script earlier in this chapter for more details.

Tip

  • If you use vi, do a global search-and-replace to get rid of the line numbering (that history introduced) at the left just use :%s/^ *[0-9]* *// (one space after the ^), and you're in business. See Chapter 4 for more about clever vi TRicks.





Unix(c) Visual Quickstart Guide
UNIX, Third Edition
ISBN: 0321442458
EAN: 2147483647
Year: 2006
Pages: 251

Similar book on Amazon

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net