1. Trang chủ
  2. » Công Nghệ Thông Tin

Sun Fundamentals of Solaris 7 Student Guide With Instructor Notes phần 6 potx

68 273 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Thông tin cơ bản

Tiêu đề Sun Fundamentals of Solaris 7 Student Guide With Instructor Notes part 6 potx
Trường học Sun Microsystems, Inc.
Chuyên ngành Solaris 7
Thể loại Student Guide
Năm xuất bản 1999
Thành phố Sunnyvale
Định dạng
Số trang 68
Dung lượng 340,66 KB

Các công cụ chuyển đổi và chỉnh sửa cho tài liệu này

Nội dung

Advanced Editing OptionsTo find a line or to search and replace and do advanced editing, usethe following options: To clear the screen or insert files, use the following options: To sear

Trang 1

The Table 9-3 shows the key sequences for character movement:.

Table 9-3 Key Sequences

h, ←, or Back Space Move left one character

l,→, or Space bar Move right (forward) one character

Control-f Page forward one screen

Control-d Scroll down one-half screen

Control-b Page back one screen

Control-u Scroll up one-half screen

Trang 2

Editing Commands

Deleting Text

To delete text, use the following options:

Table 9-4 Text Deletion Commands

X (uppercase) Delete character to the left of the cursor

the end of the line)

:5,10d Delete lines 5 through 10

Trang 3

Editing Commands

Undoing, Repeating, and Changing Text Commands

To change text or to cancel or repeat edit functions, use the followingcommands Many of these commands change you to Insert mode untilyou press Escape

Table 9-5 Editing Commands

Command Meaning

location to the end of the word

right

Trang 4

Editing Commands

Copying and Pasting Text

To copy and paste text, use the following options:

Note – Both delete and yank write to a buffer When yanking, deleting,

and pasting, the put commands insert the text differently depending

on whether you are pasting a word(s) or a line(s)

Table 9-6 Copy and Paste Commands

Command Meaning

:1,3 co 5 Copy lines 1 through 3 and put after line 5

:4,6 m 8 Move lines 4 through 6 to line 8 (line 6 becomes line

8; line 5 becomes line 7, and line 4 becomes line 6)

Trang 5

Editing Commands

Saving and Quitting Files

To save and quit a file, use the following options:

Table 9-7 Save and Quit Commands

Command Meaning

:w new_filename Write buffer tonew_filename

only permissions if you are the owner of the file.)

Trang 6

Advanced Editing Options

The vieditor includes options for customizing your edit sessions,such as:

● Displaying line numbers

● Displaying invisible characters such as tab and end-of-linecharacters

Thesetcommand is used from last-line mode to control these options.

These options can also be placed in a file the user creates in their homedirectory called exrc The set options are placed in this file, withoutthe preceding colon, one command to a line Once the.exrcfile exists,

it is read by the system each time a visession is opened

Table 9-8 Edit Session Customization Commands

:set ic Instruct searches to ignore case

:set noic Instruct searches to be case sensitive

:set list Display invisible characters such as tab and

end-of-line

:set nolist Turn off the display of invisible characters

:set showmode Display current mode of operation

:set noshowmode Turn off mode display

:set all Display all possiblevi variables and their current

settings

Trang 7

Advanced Editing Options

To find a line or to search and replace and do advanced editing, usethe following options:

To clear the screen or insert files, use the following options:

To search and replace text, use the following options:

Table 9-9 Advanced Editing/Search Commands

Table 9-10 Clearing/Insertion Commands

:r filename Insert (read) file at line after cursor

:34 r filename Insert file after line 34

Table 9-11 Search and Replace Commands

/string Search forward forstring

?string Search backward forstring

:%s/old/new/g Search and replace globally

Trang 8

Creating and Saving a File

To create a file using the vieditor:

1 Typevifilename to create the file

2 Typeito insert text

3 Press the Escape key to change to command mode.

4 Type:wq to write the file and exitvi

Note – The Escape key always puts you in command mode Use the

Escape key if you are not sure what mode you are in If you press the

Escape key while you are in command mode, the workstation beeps as

a reminder that you are already in command mode.

Trang 9

Exercise: Using the vi Editor

Exercise objective – In this exercise you will practice creating and

editing usingvi

Tasks

Complete the following step:

1 In your home directory there should be a file calledtutor.vi.Make sure that you are currently in your home directory, thenopen this file with the command:

$ vi tutor.vi

this will open up a vi tutorial Complete the lessons outlined inthis tutorial

Trang 10

Exercise: Using the vi Editor

Exercise Summary

Discussion – Take a few minutes to discuss what experiences, issues,

or discoveries you had during the lab exercises

Manage the discussion here based on the time allowed for this module, which was given

in the “About This Course” module If you find you do not have time to spend on

discussion, then just highlight the key concepts students should have learned from the lab exercise.

● Experiences

Ask students what their overall experiences with this exercise have been You might want

to go over any trouble spots or especially confusing areas at this time.

Explore with students how they might apply what they learned in this exercise to

situations at their workplace.

Trang 11

Check Your Progress

Before continuing on to the next module, check that you are able toaccomplish or answer the following:

● Differentiate between the three modes of viand identify thecommands that belong to each mode

● Exit thevieditor

● Perform search and replace functions withinvi

Trang 12

Think Beyond

Under what conditions might it be necessary for you to use the vi

editor in your work environment?

Trang 14

Upon completion of this module, you should be able to:

● Set and unset shell and environment variables for the Bourne andKorn shells

● Change the PATHenvironment variable for the Bourne and Kornshells

● Use thewhichcommand to determine which version of acommand is being used

● Use thewhereiscommand to search for instances of a command

on a system

Trang 15

Present the following question to stimulate the students and get them thinking about the issues and topics presented in this module While they are not expected to know the answer to the question, the answer should be of interest to them and inspire them to learn the content presented in this module.

Discussion – How would it be useful to customize Bourne and Korn

shells?

Additional Resources

Additional resources – The following references can provide

additional details on the topics discussed in this module:

Solaris User’s Guide, Part Number 802-6499

Solaris Advanced User’s Guide to System and Network Tasks,

Chapters 1 and 3, Part Number 801-4415-10

● Man pages for sh(1),ksh(1), and csh(1)

Trang 16

A variable is a placeholder for information to be used by the system or

user Information such as the default printer or a pathname to adirectory can be set up as a variable

Two categories of variables are discussed in the following section:

Local (shell)

Global (environment)

Two key environment variables are the PATHandENVvariables

This module covers setting and unsetting shell and environmentvariables The focus will be on the Bourne and Korn shells Appendix

A, ‘‘Features of the C Shell,” covers how variables are set in the Cshell

Trang 17

Shell Variables

Overview

When you first log in to the host, you are placed in a predefined shell

If you typesh(Bourne shell),ksh(Korn shell), orcsh(C shell) on thecommand line, a subshell is created This process can be repeated tocreate additional shells To change to the previous shell, typeexit

Shell variables (local and global) can be either user-defined or built-in,and can be customized by the user or predefined by the system

Initially, when a variable is created, it is only available to its shell oforigin This is a local variable If a new subshell is created, thevariables created in the parent shell are not available However, theparent shell is still running, and when the subshell is exited, thevariables will be available again When the shell where the variableswere created is exited, the variables of that shell are terminated Localvariables are available only to the specific shell where they are created

Trang 18

Shell Variables

Overview

To make a local variable available in all subshells, it must be exported,either by adding it to an initialization file, as discussed in Module 11,

‘‘Initialization Files,” or by exporting it on the command line

Note – See the man pages on ksh,csh, and shfor variable definitions

Trang 19

Shell Variables

Local Shell Variables

A user-defined variable enables you to determine both the name of thevariable and its value For example, a pathname could be assigned forthe on-line dictionary used in text editing programs

By convention, the Bourne and Korn shells use capital letters for shellvariable names The first command format in the following examplessets the variable based on a name and value selected by the user, whiletheunsetcommand removes the variable from the current shell andsubshells:

Command Format

VARIABLE=valueunsetVARIABLE

Trang 20

Shell Variables

Local Shell Variables

Setting a Local Variable

The echocommand simply echoes back to the screen whatever ispassed to it as an argument The dollar sign ($) metacharacter

preceding a variable name enables the system to use the value of the

variable and not the name of the variable In the above example, the

echocommand with $DTdisplays the value of DTto the screen Sincethis is a local variable, if a new subshell is opened, the variable DTisnot available

Trang 21

Shell Variables

Displaying Shell Variables

Variables and their values can be displayed by typing theset

HZ=100IFS=

LANG=CLINENO=1LOGNAME=guestMAIL=/var/mail/guestMAILCHECK=600

MANPATH=/usr/openwin/share/man:/usr/manNOSUNVIEW=0

OPENWINHOME=/usr/openwinPATH=/usr/openwin/bin:/usr/bin:

PPID=867PS1=$

PWD=/home/guestRANDOM=4188SHELL=/bin/kshTERM=sun-cmdTZ=PST8PDTUSER=guest

Trang 22

Environment Variables

Your computing environment is composed of special information, such

as the location of your mailbox and the type of terminal you have The

SunOS 5.x system software provides several default environment

variables such as PS1,HOME,LOGNAME,SHELL, and PATH Thesevariables have been defined by the shell to have a specific function.The values of these customizable variables can be changed to suit theuser’s needs

You can temporarily change your environment variables at thecommand line This affects only the current shell When you exit theshell where the environment variable has been assigned, that

environment variable is terminated or set back to its default value.Permanent changes are made by modifying the initialization files,discussed in Module 11, ‘‘Initialization Files.”

For more information on environment variables, refer to the sourceslisted in the ‘‘Additional Resources” section of this module

The Bourne and Korn shells use the same format for settingenvironment variables

Trang 23

echocommand to check if a value for a variable already exists beforesetting a new one This protects accidental overwriting of a previouslyset value.

Command Format

VARIABLE=value;export VARIABLE or

export VARIABLE=value

Creating Environment Variables

$ LPDEST=staffp; export LPDEST

Trang 24

Environment Variables

The LPDESTvariable defines the default printer.EXINITsets a last lineoption for vi

Note – Setting the EXINITvariable will override any settings saved in

a exrcfile to customize the behavior of the vieditor

Trang 25

Environment Variables

Displaying Environment Variables

Environment variables and their values can be displayed by typing the

HELPPATH=/usr/openwin/lib/locale:/usr/openwin/lib/helpHZ=100

NOSUNVIEW=0PATH=/usr/openwin/bin:/usr/bin:

WINDOW_TERMIOS=

OPENWINHOME=/usr/openwinLOGNAME=user1

MAIL=/var/mail/user1TERMCAP=sun-cmd:te=\E[>4h:ti=\E[>4l:tc=sun:

DISPLAY=:0.0SHELL=/bin/kshHOME=/home/user1TERM=sun-cmdPWD=/optTZ=US/PacificENV=/export/home/user1/.kshrcXINITRC=/usr/openwin/lib/Xinitrc

Trang 26

Environment Variables

The shell uses the PATHvariable to locate commands in directories inthe order specified by the PATHstatement

Command Format

PATH=directory:directory:directoryexport PATH

Setting the PATH Variable

The dot (.) in the PATHvariable enables the system to search thecurrent working directory for commands

You can also add to the existing path by typing the following:

Trang 27

The which Command

An incorrectly definedPATHvariable can result in users not being able

to access the right version of a command or software Many userproblems can be traced to an incorrectly definedPATHvariable

Thewhichcommand displays the pathname leading to an accessiblecommand based on your search path The output will be the name ofthe first directory in thePATHvariable that contains the command youare looking for This can be very useful if a command is not giving theexpected output Sometimes the reason for this can be that the system

is using an unexpected version of the command If the pathname is notdisplayed or is incorrect, based on your requirements, modify thePATH

variable accordingly

Command Format

whichfilename

Determining the PATH Location

Thewhencecommand, which is built into the Korn shell, does the same thing as which.

The whereis Command

Thewhereiscommand can be used to add appropriate directories toyourPATHvariable Unlikewhich, which searches the directoriesfound in yourPATHstatement, thewhereiscommand searches all ofthe directories on the system that usually have executable files located

in them Thewhereiscommand will display all directories where thecommand is located, including the appropriate man page

Command Format

$ which vi

/usr/bin/vi

Trang 28

Environment Variables

The whereis Command

Using the whereis Command

If thewhereiscommand is not found, use /usr/ucb/whereis to runthe command

$ /usr/ucb/whereis vi

vi: /usr/bin/vi /usr/ucb/vi /usr/man/man1/vi.1

Trang 29

Exercise: Using Bourne and Korn Shell Variables

Exercise objective – In this exercise, you will use the concepts taught

in this module to determine the settings of local and environmentalvariables and create a custom variable

Tasks

Complete the following steps:

1 Create a shell variable,NAME, with your name as its value Displaythe value of the new variable

2 Start another Korn shell

Does the subshell recognize the variableNAME? Why or why not? _

3 Exit the subshell Display the value of theNAME variable Is thevariable set?

6 Determine how your current PATHvariable is set

7 Add the/usr/ucbdirectory to your path and export the variable

Trang 30

coffeesdirectory.

Trang 31

Exercise: Using Bourne and Korn Shell Variables

Exercise Summary

Discussion – Take a few minutes to discuss what experiences, issues,

or discoveries you had during the lab exercises

Manage the discussion here based on the time allowed for this module, which was given

in the “About This Course” module If you find you do not have time to spend on

discussion, then just highlight the key concepts students should have learned from the lab exercise.

● Experiences

Ask students what their overall experiences with this exercise have been You might want

to go over any trouble spots or especially confusing areas at this time.

Explore with students how they might apply what they learned in this exercise to

situations at their workplace.

Trang 32

Exercise: Using Bourne and Korn Shell Variables

Exercise Solutions

Complete the following steps:

1 Create a shell variable,NAME, with your name as its value Displaythe value of the new variable

No, because the variable was only local to the shell it was created in.

3 Exit the subshell Display the value of theNAME variable Is thevariable set?

$ exit

$ echo $NAME

Yes, as this is the shell in which the variable was originally set.

4 Make theNAMEvariable an environmental variable and openanother subshell Does the subshell recognize the value ofNAME

Trang 33

Exercise: Using Bourne and Korn Shell Variables

Exercise Solutions

6 Determine how your current PATHvariable is set

$ echo $PATH

7 Add the/usr/ucbdirectory to your path and export the variable

$ PATH=$PATH:/usr/ucb; export PATH

Trang 34

Check Your Progress

Before continuing on to the next module, check that you are able toaccomplish or answer the following:

❑ Set and unset shell and environment variables for the Bourne andKorn shells

❑ Change thePATHenvironment variable for the Bourne and Kornshells

❑ Use thewhichcommand to determine which version of acommand is being used

❑ Use thewhereiscommand to search for instances of a command

on a system

Ngày đăng: 13/08/2014, 02:23

🧩 Sản phẩm bạn có thể quan tâm