惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

宝玉的分享
宝玉的分享
NISL@THU
NISL@THU
E
Exploit-DB.com RSS Feed
L
LINUX DO - 热门话题
L
Lohrmann on Cybersecurity
K
Kaspersky official blog
Project Zero
Project Zero
Cisco Talos Blog
Cisco Talos Blog
T
The Exploit Database - CXSecurity.com
P
Palo Alto Networks Blog
C
CXSECURITY Database RSS Feed - CXSecurity.com
T
Threatpost
S
Schneier on Security
G
GRAHAM CLULEY
The Hacker News
The Hacker News
T
Threat Research - Cisco Blogs
Scott Helme
Scott Helme
Threat Intelligence Blog | Flashpoint
Threat Intelligence Blog | Flashpoint
P
Privacy & Cybersecurity Law Blog
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
C
CERT Recently Published Vulnerability Notes
T
Tor Project blog
AWS News Blog
AWS News Blog
Simon Willison's Weblog
Simon Willison's Weblog
cs.CL updates on arXiv.org
cs.CL updates on arXiv.org
爱范儿
爱范儿
P
Privacy International News Feed
云风的 BLOG
云风的 BLOG
P
Proofpoint News Feed
S
Securelist
G
Google Developers Blog
The Last Watchdog
The Last Watchdog
Google Online Security Blog
Google Online Security Blog
美团技术团队
F
Fortinet All Blogs
小众软件
小众软件
Recorded Future
Recorded Future
V
Visual Studio Blog
B
Blog RSS Feed
H
Help Net Security
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
Google DeepMind News
Google DeepMind News
Blog — PlanetScale
Blog — PlanetScale
博客园 - 聂微东
Stack Overflow Blog
Stack Overflow Blog
Martin Fowler
Martin Fowler
Latest news
Latest news
Spread Privacy
Spread Privacy
H
Heimdal Security Blog

博客园 - tony

The fastest way going abroad... Love is meeting the requirments, too... Fight back and hold back... Section 14: The UNIX File System Section 13: Interactive Use of the Shell Section 12: Customizing the UNIX Shell Section 10: Editing Text with EMACS Section 9: Interaction and Job Control Section 8: Process Control and Multitasking Section 7: Pipelines and Filters Section 6: Redirecting Input and Output Section 5: Working with Files and Directories Section 4: The UNIX Shell Section 3: Logging In and Logging Out Section 2: Accessing a UNIX System Section 1: What Is UNIX? An overview about our Martch work... Obesession... Oh,,,CHANEL...
Section 11: The Execution Environment
tony · 2005-03-31 · via 博客园 - tony

CONCEPT: The exact behavior of commands issued in the shell depends upon the execution environment provided by the shell.

The UNIX shell maintains a set of environment variables that are used to provide information, like the current working directory, and the type of terminal being used, to the programs you run. The environment variables are passed to all programs that are not built in to the shell, and may be consulted, or modified, by the program. By convention, environment variables are given in upper case letters.

To view all the environment variables, use the command

printenv

You can also view a particular environment variable using the echo command:

echo $TERM

The above command echos the value of the TERM environment variable to the standard output.

The creation of the execution environment

When you log in, a sequence of events establishes the execution environment. The exact sequence of events depends on the particular flavor of UNIX, and also depends upon the default shell for your account. The following is a description of the login process for the HP-UX operating system. Other operating systems may differ.

The getty process
The getty process provides the login: prompt that you see on the terminal screen. The getty process reads your username, and invokes the login program.
The login program
The login program receives the username from getty, and prompts you for your password. Login then consults the system database /etc/passwd to verify your password. (Note that login will request your password even if there is no entry in /etc/passwd for the username you've given. That prevents someone from finding valid usernames by trial and error.) Login turns off terminal echo so that your password is not displayed on the screen.

Having verified your password, login then uses information in /etc/passwd to invoke your default shell. If no default shell is specified in the /etc/passwd entry, login starts the Bourne shell (/bin/sh).

Shell startup: System login scripts
When the shell program starts, it reads configuration files called login scripts to configure the execution environment. On HP-UX, the file /etc/profile provides initialization parameters for ksh and sh, while the file /etc/csh.login is used for csh. After the system login scripts are read, the shell looks for user-specified login scripts.
Shell startup: User login scripts
After the system login scripts are read, the shell reads user login scripts. User login scripts are kept in one's home directory, and are the means by which one can customize the shell environment. Sh and ksh look for a file called .profile. Ksh also reads a file defined in the environment variable ENV. Csh reads a file called .cshrc, and (if it is the login shell), the file .login.

Important environment variables

Here are descriptions of some of the most important environment variables, and examples of how some variables can affect the execution of commands.

TERM
The TERM environment variable defines the type of terminal that you are using. Most UNIX systems have a database of terminal types, and the capabilities of each terminal type.
PATH
The PATH variable contains the names of directories to be searched for programs that correspond to command names. When you issue a command to the shell, the shell searches sequentially through each directory in the PATH list until it finds an executable program with the command name you typed.
USER
The USER variable contains your username. Any time you access a file or directory, the access permissions are checked against the value of USER.
HOME
The HOME variable contains the name of your home directory. When you issue the cd command with no directory argument, you will be placed in the directory defined in the HOME environment variable. The HOME variable is also where the shell will look for the user login scripts.
MAIL
The MAIL variable contains the name of the directory where your incoming mail is stored. When you start a mail program, the program will look in the directory stored in the MAIL environment variable for your incoming mail messages.
EDITOR
The EDITOR variable is used by programs that must invoke a text editor to provide the ability to edit or compose documents. One example is the elm program, which is used to read and send electronic mail. If you elect to compose a new mail message while in elm, the elm program will check the contents of the EDITOR variable to determine which editor to invoke.
HOST
The HOST environment variable contains the name of the host machine that is running your shell program. When you connect to a remote host through telnet or ftp, the name of your host is relayed to the remote machine, so the administrators of the remote machine can keep track of who is connecting, and from where.

Setting environment and shell variables

The exact mechanism for setting the environment and shell variables depends upon the type of shell you're using.

sh, or ksh
To set an environment variable in sh or ksh, use the syntax VAR=value;export VAR, where VAR is the name of the environment variable and value is the value you wish to assign. Do not put spaces on either side of the equals sign. The export command instructs the shell to propagate the value of the variable to all programs that are run by the shell. If an environment variable is reset, but not exported, the change will only apply to the shell itself. To set the EDITOR variable to the value emacs in ksh or sh, use the command:

EDITOR=emacs;export EDITOR

It is also possible to unset environment variables, with the unset command. Unsetting an environment variable removes the definition of the variable.

csh
To set an environment variable in csh, use the setenv command. The command has the syntax: setenv VARIABLE value. To set the EDITOR variable to the value emacs in csh, use the command:

setenv EDITOR emacs

For more information about the shell environment, consult the manual page for the shell you're using.