Linux Unix Shell Programming Guide Learning Notes (Part III)

Source: Internet
Author: User

13th Chapter Landing Environment

When logging into the system, enter the user name and password, and if the authentication passes, enter the login environment.


Logon process

File/etc/passwd

$HOME. Profile

Custom $HOME. profile


/etc/passwd file parsing (extract one of the rows as an example):

  1234  5   6     7root:<span style= "White-space:pre" ></span>x:0:0:root:<span style= " White-space:pre "></span>/root:<span style=" white-space:pre "></span>/bin/bash  domain 1  :  login  2   domain  :  encrypted password  3   domain  :  user identification number (used to differentiate users within the system, If multiple users have the same user ID number, the system thinks they are the same user, but can have different passwords, different home directories, and different login shells.   domain 4  :  Group identification Number (identifies the group to which the user belongs, and he corresponds to the/etc/ A record in group  5   domain  :   user's full name  6   domain  :   user root directory  7   domain  :   User's default Shell

After the login is successful, the system executes two environment settings files:/etc/profile and the user root directory. Profile


/etc/profile

The file contains:

1. Global or local environment variables

2. PATH Information

3. Terminal Setup

4. Security commands

5. Date information or discard operation information


The Stty:stty is used to set the terminal characteristics.


Logout files (. bash_logout files in Ubuntu 12.04 for the user root directory):

This file holds commands that execute before the process terminates when the E x i t command is executed.


Chapter 14th Environment and Shell variables

Shell variables

Environment variables

Variable substitution

Export variables

Specific variables

Passing information to a script

Using positional parameters at the system command line


Shell variables: The shell variable is represented by a "valid" string for staging information.

Local variables: Local variables are used in scripts in the user's current shell life cycle, and users cannot set this variable to be valid in other shells or processes.

Various setup modes for variables:

Va R I a b l e-n a m e = v A l u e Set actual value to V a r i a b l e-n a m E
Va R I a b l e-n a m e + v A l u e Reset its value if v a r i a b l e-n a m E is set
Va R I a b l e-n a m e:? V A l u e if not set V a r i a b l e-n a m e, display undefined user error message
Va R I a b l e-n a m e? V A l u e if not set V a r i a b l e-n a m e, display system error message
Va R I a b l e-n a m e: = v A l u e if not set V a r i a b l e-n a m e, set its value
Va R I a b l e-n a m E:-V A l u e Ibid, but the value is not set to V a r i a b l e-n a m e, can be replaced

Clear variable: unset variable-name

Show all variables: Set (readonly shows all read-only variables)

Connection variable value: ${var1}${var2}${var3}${...} (variables can be combined by side-by

Test whether the variable has been assigned: Var1:-newvalue (Use the original value if VAR1 has already been assigned, otherwise newvalue as the new value, but newvalue is not assigned to VAR1)

To set a read-only variable, format:

Variable-name = Valuereadonly Variable-name


Environment variables

Environment variables are used for all user processes. Environment variables can be set at the command line, but these values are lost when the user logs off, so it's best to do so. Defined in P r o f i l e file. An environment variable must be exported with the E x P o r T command before it is applied to the user process. Environment variables are set in the same way as local variables.


Set environment variable Var=value:export var or

var = valueexport var

display environment variables consistent with display local variables, using ${var},

View all environment variables: env

Clear environment variable: unset var (consistent with clearing local variables)


Embedding Shell variables

Linux reserved environment variables, which are typically established in/etc/profile.

Cdpath:When a directory is on CD, look for this variable, and if present, this directory becomes the current directory.

Exinit: saves initialization options when using the VI editor.

HOME: Save the user's root directory and go directly to the directory using the CD

IFS: Specifies the shell Default domain delimiter (multiple domain separators can be specified)

LOGNAME: Save Login Name

Mail: Save the mailbox path name

MailCheck: Mailbox Detection frequency (/s), default is 60 seconds.

PATH: the directory order in which commands or script lookups are saved (frequently----and infrequently used)

PS1: basic prompt (includes Shell prompt), default root is #, other user is $

PS2: secondary prompt, multiple commands for extra rows

Shell: Save the default shell, typically configured in/etc/profile

TERMINFO: Save the terminal configuration file location.

Term: save terminal type.

TZ: Saves the time zone value.

The environment variable does not provide a default value (some of the above environment variables do not provide a default value in ubuntu12.04)

Editor: Setting the default editor

PWD: Current directory name

PAGER: Save Screen Paging command

MANPATH: Saving the Directory of man files in the system

LPDEST or PRINTER: Default printer Name


Export variables

When you export a variable using export, the child process can "see" the variable.


Positional variables (positional variable parameters ), read-only

Use the positional variables parameter to pass information to the shell script. This parameter can be as many as possible, but only the first 9 can be accessed

$0$1 $2$3 $4$5 $6$7 $8$9 ($ The name of the script and the rest as parameters)


Specific variables, read-only

Table of specific variables:

$ #传递到脚本的参数个数 $ * Displays all parameters passed to the script in a single string. Unlike positional variables, this option parameter can exceed 9 $ $ for the current process of running the script I D $! The process of the last process running in the background I-D $ @ with $ #相同, but used with quotes, and return each parameter in quotation marks $-show s H e l l Use the current option, with the S e T command function the same $? Displays the exit status of the last command. 0 means no error, and any other value indicates an error


15th Chapter quotation marks

Double quotation marks can refer to any character or string except the character $, ', \ \.

A single quotation mark is similar to a double quote, but a single quotation mark and its internal value are used as a new string if the special meaning is masked.

boy= ' Boy ' echo, like ' $BOY ', ' echo ' like ' $BOY '
The contents of the two echo outputs are not the same, and the previous ECHO has a pair of single quotes.


Anti-quote: The shell takes the contents of the backslash as a system command and executes it.
Backslash: A backslash is used to shield special characters from special meanings.


Linux Unix Shell Programming Guide Learning Notes (Part III)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.