Logging in UNIX performs several actions that prepare the user and the system for each other. These include performing system accounting, initialising the user environment, and starting a command interpreter commonly called a shell. Commands are how the user tells the system to do something. The command interpreter recognises these commands and passes the information off to where it is needed. UNIX systems originally came with a command interpreter called the Bourne Shell (usually referred to as sh). This shell is still available on most UNIX computer systems. A newer shell that is common to most UNIX systems is the C Shell (referred to as csh). Another commonly used, but not as pervasive, shell is the Korn Shell (referred to as ksh). Among different shells, there is some variation of the commands that are available.
What is a Command?
A UNIX command is a series of characters that the user types. These characters consist of words that are separated by white spaces. A white space is the result of typing one or more Space or Tab keys. The first word is the name of the command. The rest of the words are called the command's arguments. The arguments give the command information that it might need, or specify varying behaviour of the command. To invoke a command, the user can simply type the command name, followed by arguments (if any). To indicate to the shell that he is done with typing and is ready for the command to be executed, he should press Enter. For instance, the date command takes no arguments and hence, if the user enters ‘date’ at the prompt and press Enter, he should see that the computer has printed the current date and time. The echo command takes arguments. The echo command writes, or echoes, these arguments out to the screen.
UNIX commands use a special type of argument called an option. An option commonly takes the form of a dash made by using the minus sign key, followed by one or more characters. The options provide information to the command.
Redirecting Input and Output
One very pervasive concept in UNIX is the redirection of commands' input and output. Before looking at redirection though, it is a good idea to look at input and output without modification. UNIX uses the word standard in this subject to mean the default or normal mode. Thus, UNIX has the term standard input, which means input coming from the default setting, and the term standard output, which means output going to the normal place. When the user first logs in to the system, and the shell executes, the standard input is set to be what is typed at the keyboard, and the standard output is set to be the display screen.
UNIX shells have special characters that signify redirection. Output redirection is signified by the > character and input redirection is signified by the <>
cat >
where
Pipes are one of the ways UNIX allows users to combine several commands. The pipe is signified by the vertical bar (|) symbol. A pipe is a means of taking the output of one command and redirecting it as the input of another command. Assume that the user wants to know how many files exist in his current directory. The ls command will list all the files in the current directory and the number of files can be counted. But UNIX has a command that counts the number of characters, words, and lines of input and displays these statistics. Therefore, these two commands can be combined to give the number of files in the directory. One way of doing it would be
ls -l | wc -l
Combining the two commands via a pipe takes the output of the first command (the long directory listing) and gives it to the input of the second command.
Managing the Password
During login, UNIX asks the user to enter his password. If he logs in for the first time, his password is what the system administrator configured. One of the very first things he should do after logging in is change his password so that, none, including the system administrator, knows what it is. This can be done via the ‘passwd’ command. If the user forgets his password, even the system administrator, cannot look it up. There is no alternative except to reset the password to a value.
Configuring Your Environment
In order to make using the shell easier and more flexible, UNIX uses the concept of an environment. Your environment is a set of values. You can change these values, add new values, or remove existing values. These values are called environment variables—environment because they describe or define your environment, and variables because they can change.
Viewing and Setting Environment Variables
Every user's environment looks a little different. Type the env command with no arguments. The output formatting and variable names depend on which shell you are using and how your system is configured. A typical environment might include some of the following:
$ env
PATH=/usr/local/bin:/usr/xpg4/bin:/usr/ccs/bin:/opt/SUNWspro/bin:/usr/sbin:/bin:/usr/bin:/etc/b2k/install:/etc/b2k:/usr/local/lib:/oracle/ora92-64
/bin:/unix/ibin:/FINACLE/V7/app/util:/FINACLE/V7/app/cust/INFENG/exe:/FINACLE/V7/app/cust/INF
B2K_INSTALL_ID=uet7
LOGNAME=prakash1
SHELL=/bin/ksh
HOME=/users/prakash1
TERM=vt220
PWD=/users/prakash1
Some Finacleรข Related variables
$ echo $TBA_PROD_ROOT
/FINACLE/V10/app
$ echo $TBA_MRT
/FINACLE/V10/app/cust/INFENG/mrt
$ echo $TBA_SCRIPTS
/FINACLE/V10/app/cust/INFENG/scripts
$ echo $TBA_COPT_FILE
coptdefault.rip
$ echo $TBA_UTIL
/FINACLE/V10/app/util
Sometimes the number of variables in your environment grows quite large, so much so that you don't want to see all of the values displayed when you are interested in just one. If this is the case, you can use the echo command to show an environment variable's current value. To specify that a word you type should be treated differently—as a value of an environment variable—you immediately precede the variable name with a dollar sign ($). Be careful not to type any white space between the $ and the word. One of the variables in the example is HOME. You probably have this variable in your environment, too. Try to display its value using echo.
You can create a new environment variable by simply giving it a value. If you give an existing variable a value, the old value is overwritten. One difficulty in setting environment variables is that the way you set them depends on the shell you are using.
In order for your screen to display the output correctly, the environment variable TERM needs to have a reasonable value. This variable name comes from the times when terminals were used as displays (before PCs and graphics displays were common). Different terminals supported varying output control. Therefore, UNIX systems have various terminal types that they support. These are not standard, so you need to find out which terminal type to use from your support personnel. If you are using a PC to connect to a UNIX system, your PC is running a terminal emulation tool. Most of these tools have the capability to emulate several types of terminal. The important point here is to make sure that your emulator and your TERM variable are the same (or compatible). You can start off by seeing what your TERM variable is set to, by entering ‘echo $TERM’.
Shell Startup Files
Where do all these environment variables come from? Well, the system sets up various ones for the user. And each user commonly sets up others during the login process. Yes, you may be doing this without even knowing it. During the startup, which happens at login, a shell is started. This shell automatically looks in a special place or two for some startup information. One of these places is the user’s home directory. The startup information in the user’s home directory is found in special files. The specific shell the user is using will determine the name of the particular file. When the shell starts up, it examines this file and performs whatever actions are specified. One of the common actions is to give values to environment variables. This action is called initialising or setting the values.
One environment variable that is commonly set in a user's shell start-up file is the PATH variable (or lowercase path for C-shell users). This variable's value is a list of places (directories) on the system where the shell should look to locate a command. Each command the user types, is physically located in a file somewhere on the UNIX file system. It is possible for the same command name to be located in different places (and to have either the same or different behaviour when executed). Say that you have a program called my_program that is stored in your home directory, and your friend has a program called my_program, which is in her home directory. If you type my_program at the prompt, the shell needs to know where to look to find the storage location of my_program. The shell looks at the value of the PATH variable and uses the list of directories as an ordered directory search list. The first directory that has a my_program stops the search, and the shell executes that file. Because all files within a single directory must be unique, this gives a straightforward and sufficient method for finding executables (commands).
No comments:
Post a Comment