Writing a Shell Script: The Basics


Having a command history available at your shell prompt is a great tool, but what if you run variations on some of the same commands every day? What happens when you run a complicated set of commands every other week, but not necessarily on the same day of the week? These are the times when a script comes in handy.

Shell scripts won't necessarily run any faster than a C program, but because they don't have to be compiled, they can be a lot smaller. That makes them more portable as well; they will always fit on a floppy. You don't have to install extra libraries on your system unless you need to access some other language as part of your script. The process of writing scripts is also simpler and faster than any compiled language.

If you're just starting out in shell scripting, go easy. It's like a new exercise program. Don't try to do too much all at once. Concentrate on automating a process you're already doing, or would be doing if it didn't seem so complicated.

Most important, when doing scripting, do not open a word processor ever! You are just producing a text file, and an editor will do just fine. Leaving aside all the formatting that a word processor will add to your script, it also has automatic word wrap, which could easily mess things up when you run your script. Review the text editor choices in Chapter 5, and play with a few before deciding which is the best editor for you.

Note

SUSE Linux automatically creates a /bin subdirectory in your home directory. This is a good place to store your scripts because this is the first item in your search path.




SUSE Linux 10 Unleashed
SUSE Linux 10.0 Unleashed
ISBN: 0672327260
EAN: 2147483647
Year: 2003
Pages: 332

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