Shell variables: Local variables and environment variables
Basic elements:
#! /bin/bash
#
Variable
Process Control
Home: The current user's home directory
Path: The current user's executable file search path
LANG: The default language the program should use
PSI: Line Prompt
Pstree displaying processes as a directory tree
Bash--version View the version of Bash
The type command shows what command
such as: type pwd
A command line can contain more than one command, separated by semicolons.
Ls;pwd;date
Predefined variables: Store information that users don't need to care about
Set to view all local variables
Env can only view environment variables
lang=en Change the command to the English environment
Locale-a shows all languages supported by the LINX system
1. Variable A=boobooke
Input: Echo $a
Display: Boobooke
Input: Echo ${a}123
Display: boobooke123
Reset variable unset A-----Delete this variable (do not delete the variable when it is not $)
Example: #!/bin/bash
#this is .....
#name =admin
echo "${name} Welcome Boobooke"
Note: No spaces exist on both sides of the equal sign when assigning a value. Variable name = value
The value contains a space and must be enclosed in double quotation marks.
Shell variables can be written in uppercase and lowercase letters
For example 1:vi clear.sh
#! /bin/bash
#this is clear
Cat/dev/null>/var/log/messages
echo "Logs cleaned up"
chmod +x clear.sh
./clear.sh
Command substitution such as 2:vi work.sh
#!/bin/bash
echo "Your work is directory: ' pwd '"
#注意pwd要用单引号, in the ~ key
Variable reference format: $ variable name, or ${variable name}
The variable name is one character in the way one, variable name multiple characters are suggested in mode two, for example:
A=1
abc= "Hello"
Echo $a
Echo ${ABC}
Variable extension modifier: ${variable;-word}
such as: ${name1;-ganxing}, Explanation: If the name of the variable is not name1, the output
Ganxiang
Example of positional variable parameter: #!/bin/bash
echo "This script's name is $"
echo "1th parameter is $"
echo "2nd parameter is $"
This article is from the "Day to survive, Night development" blog, please be sure to keep this source http://perter.blog.51cto.com/1962646/1840839
Shell's underlying syntax