Sample one: name = 12 & attention, name = 12 is the wrong wording, because there are 12 spaces in front, and there is no character jump Note: The instructions are executed from left to right, when there is single or double quotation marks casement use, will first perform internal quotation marks. Sample II: name = VBird \ '\ name & uses hop single quote character, null character into an ordinary character Sample III: Increase the "yes" after the name string variable name=${name}yes
This is a casual record notes: to write their own
First statement: Special characters: line breaks, whitespace, etc.
1. Special characters within double quotes, you can retain the original characteristics: eg: "$ a" get the contents of a variable, rather than a
2. The special characters in single quotation marks, can not retain the original characteristics, only as a general character: eg: '$ a' $ a can only be a string.
3. Available escape character '\' special character will become general character, it is like C language escape characters (such as output% d, we must write %% d): eg: "\" says a space.
4. The variable amplification content, using ':' eg: PATH = $ {PATH}: / home / bin thus added to "/ home / bin" contents
5. If other variables need to be performed in the subroutine, it is necessary to use 'export' to the environment variable into a variable, eg: export PATH
Subroutine: In my current shell, to enable another new shell, so that a new shell is a subroutine. In general, the parent program of a custom variable can not be used in the subprogram, but after export by the variable changes to the environment variables can be used
name = VBird & parent program shell bash & into the so-called subroutines name $ echo & outputted empty, because the variable parent program can not be used in the subroutine Exit & Exit subroutine name Export & will become variable environment variable name bash $ name echo & output VBrid exit
Environment variable function
Instructions often used for env, export these two instructions
& The following is a list of all environment variables in two ways
method one:
env
Second way:
export
Common environment variables:
SHELL: tell us, the current environment which is only used shell program, linux default / bin / bash
MAIL: When we use this command when receiving mail, the system will be to read the letter in the mailbox
PATH: Search path for executable files
Observe all variables set (containing environment variables and custom variables)
in bash: Environment variables, variables related to the operation of the interface, user-defined variables
Note: By default in linux, uppercase variables set to the variables within the system is generally required.
The more important variables within the system needed
1.PS1 (prompt character set)
2. $ :( PID on the shell) indicates the current shell thread code
export: custom variables turn into an environment variable
The variable is set to use environment variables: For example, for a file, when I need to use several different routines to access the same file, if not export, you must create a variable stored in each program location of the file. This is very troublesome. If you use the export, you only need to create a variable in the parent program to store the location of the file, and then become environment variables export, so we can use this subroutine variables.
Why environment variables can be used in routine?
1. When you start a shell, shell operating system will give a block of memory, this memory variables within the subroutine allows access
2. If the custom variables become the parent program using the export environment variable, the variable will be added to the memory block.
3. When loading a shell again, will the parent shell sub-shell environment variables memory block into your own environment variables memory block
Using the keyboard input read instructions: Example: Enter your name thirty seconds the Read -p "enter his name in the 30s:" -t 30 name Display: Please enter his name in the 30s: Xiao Ming echo ${name} Display: Xiao Ming declare command: the reader's own learning
Note: bash for variables There are several basic definitions:
1. The default type is a string variable, eg a = 1 + 2, echo $ {a} 2 + 1 output result, instead of 3
2. The default can only reach a maximum integer such as 1/2, it is considered to be 0
For variables '-' minus use
var = $ {str-expr} no value for str, var = expr has a value for str (also considered to have a null string value) var = $ str
var = $ {star: -expr} st for no value, var = expr to the empty string str, var = expr for non-empty string str, var = $ str
For variable '? 'C somewhat similar language ternary operator, but also a bit different
var = $ {str?} does not exist, if, str exists, var = $ str, whether the person, var = absent