|
My ClickWorld.com | ||||
|
|
Your Ultimate Guide to Programming.What is a shell?The shell is the layer around the Unix operating system.The shell’s job is to translate the user’s command lines into operating system instructions. For example, consider this command: sort –n phonelist > phonelist.sorted This means, sort the lines in the phonelist file in numeric order, and put the result in the file phonelist.sorted. Remember that the shell itself is not Unix – just the user interface to it. Unix is one of the first operating systems to make the user interface independent of the operating system. When you log on, the UNIX system starts running a program that acts as an interface between you and the
UNIX kernel. This program, called the UNIX shell, executes the commands that you have types on the keyboards.
When a shell starts running, it gives you a prompts and waits for your commands. When you type a command
and press For example: A shell command can be built-in or external. The shell has the code for executing built-in command, but the code for an external command is in a file. To execute an external command, the shell searches several directories, one by one, to locate the file that contains the code for the command. If the file is found, it is executed if it contains code (binary or shell script). Then names of the directories that the shell searches to locates the file for an external command form what is known as the search path. The search path is stored in a shell variable called PATH. You can change the search path for your shell by adding new directory names in PATH or by deleting existing directory names from it. Directories:Let’s review the most important concepts about directories. The fact that directories can contain other directories leads to a hierarchical structure, more popularly known as a tree, for all files on a Unix System.All files can be named by expressing their location on the system relative to the root directory; such names are
built by listing all of the directories names beginning at the root, separated by slashes (/), followed by the
file’s name. This is an absolute pathname.
For Example to print the tempfile.txt in the common area:
The Working DirectoryOf course, it is annoying to have to use the full pathname (absolute pathname) whenever you need to
specify a file. So there is also the concept of the working directory (aka the current directory), which is the
directory you are “in”. If you give a pathname with no leading slash, then the location of the file is worked
out relative to the working directory. Such pathnames are called relative pathnames; you’ll use them much more
often than full pathnames.
For Example: The working directory is /common/cis/hart; you want to print the tempfile.txt in the common area. Tilde Notation or HOME shell variableThe Korn shell has a way of abbreviating the home directories – the tilde (~) – stands for your home
directory - /home/userid . To list the contents of the tempfile.txt located in the ciss-102 directory you can
use the following command: A shell variable is a name that has a value associated with it. The shell has two types of variables – local and environment. Environment variables are available to use (or known) in the user’s total environment. Meaning they are known in programs, in subdirectories, etc. The Korn Shell keeps track of several environment variables. By convention, environment variables names are UPPER CASE. shell OptionsThe KornShell lets you set options to control its behavior. To do this you use the set command. This allows you to change the shell’s behavior.
Option Description
emacs allows command line editing using the basic emacs commands
Try It. Shell Start-up FilesThe actions of each shell, the mechanics of how it executes commands and programs, how it handles the command and program I/O, and how it is programmed, are affected by the setting of certain environment variables. This is the file, where you change how your shell “looks and feels”. Each time you login to the Unix Box – a file .profile which MUST be located in the home directory, is executed. The .profile contains the initial settings of important environment variables for eh shell and some other utilities. The .profile sets the shell’s default options. If you want to change how the shell behaves you make those changes to the environment file. The environment file that we will use is the .kshrc file. export: Creating Environment VariablesAll shells use environment variables to manage individual preferences. The Korn Shell using the export statement to change the value of an environment variable, so it will be kept when the session ends.
[academ]$ PS1=’This is my new prompt> ’ |
|
||
|
| ||||