Sie sind auf Seite 1von 11

2/15/13

devices. terminals and csh part 1 of 2

UNIX
Copyright B. Brown, 1988-2000. All rights reserved. March 2000.

Assignment 4: Terminals, Devices and csh /1 Exercise Objectives


This module introduces UNIX devices, terminals and the C shell. At the end of this module you will have an understanding of the UNIX directory structure configure your terminal type use commands associated with controlling your terminal invoke the C shell and configure its environment write simple C shell scripts

Devices
The UNIX operating system treats all devices as byte streams. To programs, devices look like files, and appear as filenames in the /dev sub-directory. Typical devices are
ds die ik rvs trias emnl pitr rnes /e/d dvhx /e/tx dvty /e/p dvlx

Unix directory structure


The directory structure of a typical UNIX system is
/ /i bn /e dv /t ec /i lb /m tp /s ur /s/i urbn /s/nld uricue /s/i urlb /s/es urnw /s/po ursol /s/m urtp ro drcoy ot ietr Ui uiiis nx tlte seildvcs pca eie amnsrtv porm adtbe diitaie rgas n als lnug lbais agae irre tmoayfls eprr ie ue sbdrcoyae sr u-ietr ra Ui uiiis nx tlte icueflsue b lnug poesr nld ie sd y agae rcsos acielbais tx poesn mco rhv irre, et rcsig ars nw es solflsfrpitn po ie o rnig tmoayfls eprr ie

Hardware devices
Hardware devices appear as filenames in the /dev subdirectory.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 1/11

2/15/13

devices. terminals and csh part 1 of 2

/e/osl dvcnoe /e/p.2 dvl0. /e/d.1 dvh0. /e/d0 dvwn /e/d.1 dvf0. /e/mm dvke /e/e dvmm /e/t0. dvty.. /e/tp. dvty0. /e/ul dvnl

sse cnoe ytm osl sse pitr ytm rnes hr dss ad ik hr ds cnrle ad ik otolr fop dss lpy ik kre mmr enl eoy sse mmr ytm eoy trias emnl ped trias suo emnl nl dvc ul eie

Block And Character Devices


Unix devices are either block or character devices. Examples of block devices are disk drives and tape systems; printers and terminals are character devices. When listing devices in the /dev directory, the device type is indicated as a block or character device (the first character position of the file attributes). $ ls -l /dev/tty crw-rw-rw 1 bin terminal 3, 0 Aug 7 08:38 /dev/tty The utility mknod builds special files, and accepts a switch indicating the device type.

Devices Are Treated Like Files


Because hardware devices appear as filenames, they can be treated just like files. This means redirection can be applied to devices also. Consider the following code example, which uses the who command to identify the terminal used by the user, then redirects the output of the date command to the terminal in use. $ who brian ttyp09 Aug 27 07:33 $ date > /dev/ttyp09

Exercise 1
Identify your ttyp number (by using who), and with a command syntax based on echo, send the current date to the terminal device. Enter the command you used to do this is the space provided below. _________________________________________________ What type of device is the ttyp device? Cross out that device which does not apply. block character
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 2/11

2/15/13

devices. terminals and csh part 1 of 2

Review 1: Devices
The two types of devices used by Unix systems are ________________________ _________________________ All devices appear as filenames under which subdirectory _________________________________________________ The filename associated with the system console device is _________________________________________________ What device name do you think is associated with the system line printer (hint: look in the /dev subdirectory)? _________________________________________________ Remote terminals are associated with the filenames _________________________________________________ The null device is different from other devices in that when data is written to it, the data _________________________________________________

TERMINALS
All users communicate with the Unix host via a terminal. The terminal type is displayed each time the user logs in, and can be altered to suit a wide variety of terminal types. Each terminal type uses a different set of command codes for cursor positioning and editing. By matching the physical terminal type with the software entry, the Unix system can use the appropriate software driver.

Changing The Terminal Type


When a user logs in to a Unix system, unless the terminal type is specified in the .profile script, the system will ask the user to specify the terminal type. Common terminal types are ansi vt100 wy30 The terminal type is stored in the users .profile file in their home directory. If the terminal type is always the same, then its best to set this correctly so the shell knows the terminal type being used. This eliminates the need for the user to specify the terminal type at login time.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 3/11

2/15/13

devices. terminals and csh part 1 of 2

The Bourne shell uses the following entry to specify the terminal type. TERM=termtype; export TERM The terminal type is easily set within the shell by typing this at the command prompt. To make the change permanent, the entry in .profile must be edited.

The /etc/termcap File


This file contains the definitions of all the different terminals and code combinations supported by this Unix system. It can be viewed using the command 'cat /etc/termcap | more' You can look at this file to identify all the terminal types supported by the Unix host.

Commands Associated With Terminals


clear ct clears the terminal screen. spawn getty to a remote terminal. Dials via modem, then displays login prompt on remote terminal.

disable disables a terminal or printer. enable enables a terminal or printer. lock locks a terminal using a password. Terminal remains locked till the password is re-entered. setcolor allows changing of screen attributes. May not work on all terminals (uses escape code sequences). setkey works only on the system console. Assigns a string to a function key. stty tabs tput tset tty sets options for terminals. sets tab stops on the users terminal. The terminal must support remotely-settable hardware tabs. queries the terminfo database for attributes related to the current terminal setting. used for setting erase and kill characters, setting or resetting delays, terminal types etc. prints the pathname of the users terminal on stdout.

Review 2: Terminals
Identify your terminal number _________________________________________________ Show how to change the terminal type to wyse30 using the Bourne shell. _________________________________________________
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 4/11

2/15/13

devices. terminals and csh part 1 of 2

What file holds all the terminal definitions? _________________________________________________ A user is going for morning tea but does not want to log off the system. They are worried that another user might try to gain access whilst they are not present. What should they do? _________________________________________________ _________________________________________________ How does the tabs command affect the terminals output? _________________________________________________ Which command would the system console operator use to assign keywords to function keys. _________________________________________________ The command setcolor does not work on my terminal? What is a possible cause? _________________________________________________ _________________________________________________

Using stty
This sets certain terminal I/O options for the device associated with stdin. When typed without arguments, it displays the current settings of these options. The format of the command is stty [-a] [-g] [options] The various options supported are parity character size baud rate stop bits flow control, cts, xon-xoff upper-lowercase translation cr/cr-lf translation, delays after cr/cr-lf, formfeed, tabs echo, full/half-duplex A - sign preceding an argument turns that option off. Some examples are, stty -echo ;suppress echoing of input
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 5/11

2/15/13

devices. terminals and csh part 1 of 2

stty erase # ;set erase character to # stty quit @ ;set SIGQUIT to @ (initially ctrl-\)

Using tput
This command uses the terminfo database to make the values of terminal dependent attributes available to the shell. The format of the command is tput -Ttermtype attribute Some examples are, tput clear ;echo clear screen sequence tput cols ;print the number of columns bold=`tput smso` norm=`tput rmso` echo "${bold}Hello there${norm}" The last example assigns the codes for bold-on and bold-off to shell variables. These are then used to highlight a text string.

Using tset
This command is used to specify the erase and kill characters for the terminal, as well as specifying the terminal type and exporting terminal information for use in the shell environment. This command is used at login time (.profile) to determine the terminal type. Examples of commands are, tset vt100 ;set terminal type to vt100 tset -e# ;set erase character to # (default ctrl-H) tset -k@ ;set kill character to @ (default ctrl-U)

Review 3: stty, tput and tset


Show, for each of the following, how to set the erase character to @ tset .......................................................... stty .......................................................... How do you clear the terminal screen?

uva.ulb.ac.be/cit_courseware/unix/unix15.htm

6/11

2/15/13

devices. terminals and csh part 1 of 2

.......................................................... I am using an ansi terminal. Show two different commands I can use to set the terminal type. .......................................................... ..........................................................

csh
The C shell is an alternative to the Bourne shell, used in previous modules. This section explains the features and syntax of the C shell. The objective of this section is to familiarise the user with the common features of the C shell interface. This exposure should make the user more proficient in UNIX, extend the base of knowledge, and lead to greater productivity. Quick Overview The C Shell varies from the Bourne shell by providing
aiss lae hsoylss itr it ;iia t selvrals smlr o hl aibe ; ls o peiu cmad ue dfeetsna a it f rvos omns sd ifrn ytx

Each of these features will be explained in the sections that follow.

Invoking The C Shell


Type the following command to invoke the C shell. $ csh The shell, when invoked, looks for the following files.
.sr chc .oi lgn cmad t eeuewe selivkd omns o xct hn hl noe cmad t eeuea lgntm omns o xct t oi ie

Note that the .login file is the C shell equivalent of the Bourne shell file .profile.

Typical commands placed in the .login file are set ignoreeof set mail=(/usr/spool/mail/username) The purpose of ignoreeof prevents the user from using ctrl-d to exit the shell; in this instance, the user must explicitly type the command exit.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 7/11

2/15/13

devices. terminals and csh part 1 of 2

The C Shell Prompt


After processing the .cshrc and .login command files, the C shell prompt is displayed. Note that it differs from that used by the Bourne shell ($). % Note: In our version of LINUX, the csh prompt is displayed as > A user logs out of the C shell by using the logout command. The C shell will process the commands stored in the file .logout at this time, if the file exists in the users home directory, before logging the user off the system.

C Shell Variables
The set command assigns values to shell variables. The syntax is identical to that of the Bourne shell. set path=(. /bin /usr/bin /usr/local) The . indicates that the current directory is to be searched first. When commands are added, the rehash command is used to get the shell to recompute its internal table of commands.

Some of the variables maintained by the C shell are,


pt ah pop rmt hm oe inref goeo sel hl sau tts ncobr olbe drcoysac pt ietr erh ah pop smo,% rmt ybl hm drcoy oe ietr inr crgoe tld selbigue,/i/s hl en sd bnch selsau,0 hl tts oewieflsuig> vrrt ie sn

Some of the variables are either set or unset; they have no specific value. One such example is the variable ignoreeof. The following commands turn it on (set) and turn it off (unset) respectively. set ignoreeof unset ignoreeof Type the following command to set ignoreeof. % set ignoreeof

Another handy variable is noclobber. When the shell redirects the output of a command using >, the file is created anew.
uva.ulb.ac.be/cit_courseware/unix/unix15.htm 8/11

2/15/13

devices. terminals and csh part 1 of 2

Type the following command to set this variable % set noclobber The C shell will now not over-write existing files.

Type the following command % date > now Repeat the last command again. What happened? _________________________________________________ _________________________________________________

Now, type the command % date >! now What happened? _________________________________________________ _________________________________________________ In the second instance, using the >! redirection, no error message was displayed, and the file was created anew. This provides a means of deliberately over-riding the noclobber setting.

Using The C Shell History List


The C shell maintains a history list of the previously used commands. The number of commands remembered is determined by the value assigned to the history variable. The use of a history list allows repeating previous commands or correcting minor typing mistakes. Examples for the syntax of accessing the history list is (do not type these!),
hsoy itr ! ! ! * ! $ ! c ls peiu cmad it rvos omns rpa ls cmad eet at omn ls agmnst tepeiu cmad at ruet o h rvos omn ls agmn t tepeiu cmad at ruet o h rvos omn ls cmadue wihsatdwt '' at omn sd hc tre ih c
9/11

uva.ulb.ac.be/cit_courseware/unix/unix15.htm

2/15/13

devices. terminals and csh part 1 of 2

! 2

cmad2i tehsoyls omn n h itr it

Type the command history to view previously entered commands. % history What history command can you use to repeat the command 'date > now' _________________________________________________

Review 4: csh, variables and history


The C shell prompt is _________________________________________________ The C shell variable ignoreeof, when set, causes the shell to _________________________________________________ _________________________________________________ _________________________________________________ The C shell executes two files when it starts. The names of the two files are, _________________________________________________ _________________________________________________ The C shell variable noclobber, when set, causes the shell to _________________________________________________ _________________________________________________ _________________________________________________ To set the C shell variable ignoreeof, the following command is used. _________________________________________________ What do each of the following C shell commands do (you may wish to review the entry for csh in the on-line manual with the command man csh)?
hsoy itr ! * _________________________ ________________________ _________________________ ________________________
10/11

uva.ulb.ac.be/cit_courseware/unix/unix15.htm

2/15/13

devices. terminals and csh part 1 of 2

! ! ! d

_________________________ ________________________ _________________________ ________________________

Home | Other Courses | Assessments | Notes | Tests

Copyright Brian Brown, 1988-2000. All rights reserved.

uva.ulb.ac.be/cit_courseware/unix/unix15.htm

11/11

Das könnte Ihnen auch gefallen