AccessMyLibrary : Search Information that Libraries Trust AccessMyLibrary | News, Research, and Information that Libraries Trust

AccessMyLibrary    Browse    P    Personal Computer World    NOV-05    Hands on - Linux/unix - Come out of your shell. The easy way to create a script to help automate a tedious task.(Column)

Hands on - Linux/unix - Come out of your shell. The easy way to create a script to help automate a tedious task.(Column)

Publication: Personal Computer World

Publication Date: 01-NOV-05

Author: Shilliday, Barry
How to access the full article: Free access to all articles is available courtesy of your local library. To access the full article click the "See the full article" button below. You will need your US library barcode or password.

Bookmark this article

Print this article

Link to this article

Email this article

Digg It!

Add to del.icio.us

RSS

COPYRIGHT 2005 VNU Business Media Europe

Byline: Barry Shilliday.

Last month we introduced the Unix shell. We looked at its purpose, how to run commands and pass simple arguments or options, and we looked at environment variables. This month we will take this further and look at some simple shell scripting.

A shell script is a program that runs inside the shell. It is not as versatile as a generic programming language such as C, but it provides all the basic necessities. While other programming languages are concerned with allowing you to create utilities and applications, a shell script is designed to allow you to control the way other programs or utilities are run. In its simplest form, it is a series of programs to run and, like a simple program, is executed from top to bottom. When the end of the script is reached, the shell script ends.

So here's our basic shell script. Run an editor (such as vim or kate) and create a file called test.sh containing the following:

echo "Hello World"

echo "This is today's date:"

date

To run the script, just execute a shell with the filename as an argument:

$ bash test.sh

This command launches a new shell, which then goes ahead and executes the commands inside the file. If you remember from last month, the echo command simply returns whatever it's given, so in a script it acts like a print command. The date command returns the current date and time. In this instance, there is no difference between running each of these commands at the command line and executing them together in a script. In fact, there is very little real difference between shell scripts and interactive shell sessions in general; the shell constructs work interactively too, as we will see later.

Of course, shell scripts wouldn't be very useful at all if they were limited to running sequential commands alone. Before going any further, we should clean up the script above to use a more standard form. As it stands, the script is just a text file. It's not a good idea to have scripts like this, as there's no way of knowing how to run the script, which shell to use (see box) or, indeed, if it really is a shell script.

Unix systems use a 'magic number' to identify files. The first few bytes of...

Read the full article for free courtesy of your local library.


More Articles from Personal Computer World
Hands on - Digital imaging & video - Emulating photographic filters. U...
November 01, 2005
Reviews - Dual-core pc group test - Two cores are better than one. Wit...
November 01, 2005
Reviews - Anti-spyware group test - Espionage exposed. As spyware and ...
November 01, 2005
Reviews - Network cameras group test - Network cameras. View live foot...
November 01, 2005
Reviews - Inkjet photo paper group test - The great paper chase. Using...
November 01, 2005

What's on AccessMyLibrary?

31,982,826 articles
in the following categories:

Arts, Business, Consumer News, Culture & Society, Education, Government, Personal Interest, Health, News, Science & Technology


© 2008 Gale, a part of Cengage Learning  | All Rights Reserved | About this Service | About The Gale Group, a part of Cengage Learning
                                            Privacy Policy | Site Map | Content Licensing | Contact Us | Link to us
      Other Gale sites: Books & Authors | Goliath | MovieRetriever.com | WiseTo Social Issues