1. Trang chủ
  2. » Ngoại Ngữ

Sun Fundamentals of Solaris 7 EU-118 Student Guide With Instructor Notes phần 8 pdf

63 365 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 EU-118 Student Guide With Instructor Notes Part 8
Tác giả Sun Microsystems, Inc.
Trường học Sun Microsystems University
Chuyên ngành Solaris 7 Operating System
Thể loại Guideline
Năm xuất bản 1999
Thành phố Santa Clara
Định dạng
Số trang 63
Dung lượng 349,48 KB

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

Nội dung

Upon completion of this module, you should be able to: ● Name the different initialization files for the Bourne, Korn, and Cshells ● Identify the initialization file used by the Common D

Trang 1

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 2

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

Trang 3

Think Beyond

Setting variables at the command line every time you log in can betedious How could you make these variable definitions a permanentpart of your environment? How might a system administrator definevariables for all users on a system?

Trang 4

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

● Name the different initialization files for the Bourne, Korn, and Cshells

● Identify the initialization file used by the Common DesktopEnvironment

● Define the purpose of initialization files

● Describe where the initialization files are located and what types

of settings can be defined

● Set the ENV variable to enable the.kshrcfile to be read

Trang 5

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 – Certain types of information, such as your default

printer, are set each time you log in What other types of customizablesettings could be set at the beginning of each session?

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

Trang 6

Features of Initialization Files

Overview

Initialization files contain a series of commands and variable settings

that are executed when a shell is started These files customize theenvironment for the system and the user

There are two levels of initialization files The first level is wide System initialization files are maintained by a system

system-administrator and reside in the /etcdirectory

Trang 7

Features of Initialization Files

When a predefined environment variable is placed in one of thesystem-wide initialization files, it is recognized globally in any shell orsubshell Users can customize many of these variables for their ownenvironment by placing them in the initialization files in their homedirectory To make the customizations available to all subsequentshells, the variable must be exported Unlike variables, commandscannot be exported If commands are used in the initialization files,they must be placed in the secondary initialization files in order to beread each time a subshell is opened

Table 11-1 User-Specific Initialization Files

Shell System-Wide

(Read First)

User-Specific (Read Second)

Bourne 1./etc/profile 2.$HOME/.profile

Korn 1./etc/profile 2.$HOME/.profile

Trang 8

Features of Initialization Files

The /etc/profile Script

When a Bourne or Korn shell user logs in, the system reads the

/etc/profilefile first, and then it reads the user’s.profilefile,and, for Korn shell users, the kshrcfile This means that the user’spreferences for variable settings can override the default settings thatappear in the /etc/profilefile

The /etc/profilefile:

● Exports environment variables such asLOGNAMEfor login name

Trang 9

User-Specific Initialization Files

Login Sequence

When you log in to your system, the system and user’s initializationfiles for the appropriate shell are read, and the tasks defined in theinitialization files are executed

The initialization files provide great flexibility to the user forcustomizing their environment Generally, these files are set up astemplates by the system administrator, and then modified by the user

Trang 10

User-Specific Initialization Files

Login Sequence

The user-specific initialization file(s) are stored in the home directory

of the user These initialization files can perform all or part of thefollowing:

● Set the default prompt

● Define the default printer

● Set default permissions

● Set the default terminal type used byviand other tools

● Tell the shell where to look for new mail

● Setnoclobberto prevent overwriting of files during redirection

● Set the command path to the user’s specification

● Set up custom commands

Trang 11

User-Specific Initialization Files

Trang 12

User-Specific Initialization Files

Login Sequence

When you first log in to the system, you are placed in the default shell

as defined by the /etc/passwdentry for your account

As described in Module 10, ‘‘Bourne and Korn Shell Variables,” if anew subshell is created by entering the command sh(Bourne shell),

ksh (Korn shell), or csh(C shell), a subshell is created This processcan be repeated to create additional subshells To change to theprevious shell, type exitor press Control-d

The initialization files are read as shown in Table 11-2 The profile,

.kshrc,.login, and cshrcfiles are assumed to be in the user’shome directory

Table 11-2 Initialization Files Read Process

Shell Read During Login Read Opening Shell

Bourne /etc/profile and.profile

Korn /etc/profile,.profile, and

.kshrc

.kshrc

C /etc/.login,.cshrc, and.login cshrc

Trang 13

User-Specific Initialization Files

The dtprofile

For CDE users there is another initialization file called dtprofile

which resides in the user’s home directory and determines settings forCDE This file is generally set up to be standard system wide and iscreated in a user’s home directory the first time the user logs in toCDE In versions of CDE shipped with Solaris 2.6 and later, the.dtprofilecauses the system to read a Korn shell user’s.kshrcfileeach time a terminal window is opened within CDE, and the

.profileand kshrcfiles each time a console window is opened.Both initialization files are also read when CDE initially starts up

For versions of CDE shipped with versions of Solaris earlier than 2.6, itwas necessary to make changes to the.profileor.loginfiles asrecommended within the standard.dtprofile, and then uncomment(remove the # sign from in front of) the line reading

DTSOURCEPROFILE=true

IfDTSOURCEPROFILEline is commented out, none of the initialization files are read (with the exception of.dtprofile).

Trang 14

User-Specific Initialization Files

Shells

The login shell is assigned by the system administrator as part ofcreating a user account The login shell determines which initializationfiles are read during login

Bourne Shell

The Bourne shell uses profile, a user-specific initialization file toset the user’s environment The.profilefile is only read once duringlogin

Trang 15

User-Specific Initialization Files

When you log in to the system, the.profile file is read Then, if the

ENVvariable in the.profile file is assigned and exported, the

.kshrcfile is read The.profile file is only read once, while the

.kshrcfile is read every time a new Korn shell is opened

Many Korn shell commands cannot be executed by the Bourne shelland therefore should not be placed in the.profile file These Kornshell specific commands and features should be placed in the.kshrc

file

The contents of the.kshrc file, discussed in detail in Module 12,

‘‘Basic Features of the Korn Shell,” can include

$ ~/.kshrc

$ ~/.profile

Trang 16

User-Specific Initialization Files

To have the system reread the loginor.cshrcfile after changeshave been made, the user can either log out and log back in, or typethe following from the command line:

% source ~/.login

% source ~/.cshrc

Trang 17

The ENV Environment Variable

TheENVvariable defines the path to the kshrcfile This variable must

be stored in the.profilefile to inform the system that the.kshrcfileexists and is to be read when creating a Korn shell

Command Format

ENV=$HOME/filename;export ENV

This command sets the environment variable to point to the.kshrc

file in the$HOMEdirectory.HOMEis a variable that is defined by thesystem to be the absolute path to the user’s login directory PrecedingtheHOMEvariable with the dollar sign ($) metacharacter enables thesystem to use the value ofHOMEin the specified location

$ ENV=$HOME/.kshrc; export ENV

Trang 18

The ENV Environment Variable

When theENVvariable is placed in the.profilefile and read by othershells (such as the Bourne shell), it does not act as a pointer to the

.kshrcfile This variable has no meaning outside of the Korn shell

Trang 19

Exercise: Setting Initialization Files

Exercise objective – In this exercise, you will demonstrate an

understanding of the concepts covered in this module

Tasks

Write the information requested in the space provided

1 What is an initialization file?

2 Where are the user-specific initialization files stored?

_

3 Name the user-specific initialization files for the Korn and C shells.

4 What is the initialization file for CDE called?

_

5 Describe or name at least three settings that can be stored in the

.profile or.logininitialization file for each shell

_

6 Describe or name at least two settings that can be stored in the

.kshrcor.cshrc file

Trang 20

Exercise: Setting Initialization Files

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 21

Exercise: Setting Initialization Files

Exercise Solutions

Write the information requested in the space provided

1 What is an initialization file?

An initialization file is an environment file that generally resides in the user’s home directory and is used to customize the user’s environment.

2 Where are the user-specific initialization files stored?

User-specific initialization files are stored in the user’s home directory.

3 Name the user-specific initialization files for the Korn and C shells

.profileand.kshrc(Korn shell) and.loginand.cshrc(C shell)

4 What is the initialization file for CDE called?

.dtprofile

5 Describe or name at least three settings that can be stored in the

.profile or.logininitialization file for each shell

Time zone, terminal type,PATH, user’s login name, default printer, local

language, and where shell should look for new mail and environment variables.

6 Describe or name at least two settings that can be stored in the

.kshrcor.cshrc file

Aliases, history, and a customized prompt.

Trang 22

Check Your Progress

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

❑ Name the different initialization files for the Bourne, Korn, and Cshells

❑ Identify the initialization file used by the Common DesktopEnvironment

❑ Define the purpose of initialization files

❑ Describe where the initialization files are located and what types

of settings can be defined

❑ Set the ENV variable to enable the kshrcfile to be read

Trang 23

Think Beyond

What kinds of settings and customizations would you put into yourinitialization files at work?

Trang 24

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

● Use basic shell quoting

● Customize the Korn shell

● Customize commands in the Korn shell using the aliascommand

● Review previously executed commands in the Korn shell using the

historycommand

● Set the command-line editor and edit previously issuedcommands

Trang 25

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 – What customizations do you perform repetitively that

you would like to set automatically?

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

Trang 26

Korn Shell Overview

The Korn shell uses the Bourne shell as a basis for its features Theseshared features include a login initialization file and variables Inaddition, the Korn shell provides command tracking, command-lineediting, and command substitution

The initialization file used for storing this information is the kshrc

file

To learn about comparable features in the C shell, see Appendix A,

‘‘Features of the C Shell.”

Trang 27

Korn Shell Features

$ echo "***host is $WO*** `date`***"

***host is venus*** Jul 4 11:05:31 PDT 1999***

Trang 28

Korn Shell Features

Trang 29

Korn Shell Features

Custom Prompts

The first line of this example assigns the prompt to the conventional$

with a character string (Good morning) The second line demonstratesusing a command (uname -n)with the history line indicator (!)for aunique prompt This command will show the name of the host onwhich you are working The third line sets a variable and the fourthline uses the variable’s value for the prompt

The prompt can also be customized to reflect the current workingdirectory

Trang 30

Korn Shell Features

Aliases

Aliases provide an excellent way to:

▼ Substitute a short command for a long one

▼ Create a single command for a series of commands

▼ Create alternate forms of existing commands

▼ Change a command set

Trang 31

Korn Shell Features

To display aliases, use thealiascommand with no argument

Displaying All Aliases Set for the Current Session

Some of the aliases are set system wide as part of the Korn shell

$ alias

autoload=’typeset -fu’

bye=exitc=clearcopy=’cp -i’

functions=’typeset -f’

h=historyhistory=’fc -l’

Trang 32

Korn Shell Features

Aliases

Removing an Alias in the Current Shell

You can unset a previously defined alias with the unaliascommand

Ngày đăng: 24/07/2014, 02:20

TỪ KHÓA LIÊN QUAN

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