One
You can use declare
command creates a variable named tmp variable: $ tmp = shiyanlou
Reads the value of the variable, you can use echo
commands and $
symbols ($ symbol used to represent the reference value of a variable, beginners often forget to enter),
We variable type usually involve three ways:
- Current Shell process private tmp variable user-defined variables, such as the above, we create only valid in the current Shell.
- Shell itself is built-in variables.
- Custom variables derived from environment variables.
There are also three commands related to the three environment variables: set
, env
, export
.
Press the lifetime of variables to divide, Linux variables can be divided into two categories:
-
Permanent: the need to modify the configuration file, variable permanent;
-
Temporary: Use the command-line statement to export, variable fail when you close the shell.
Here are two important documents /etc/bashrc
(some Linux do not have this document) and /etc/profile
they were stored in a shell and environment variables, the .profile current user only permanent.
Written in /etc/profile
there is permanent for all users, so if you want to add a permanent environment variable, just open /etc/profile
, add the final environment variable you want to add a thousand million.
two
Adding a custom path to "PATH" environment variable, $ the PATH = $ the PATH : / Home / shiyanlou / mybin, pay attention here, be sure to use absolute paths.
Echo $ "$ PATH = PATH: / Home / shiyanlou / mybin"
Variable modifications:
Variable arrangement | Explanation |
---|---|
${变量名#匹配字串} |
Start back from scratch match, delete data in line with the shortest matching string |
${变量名##匹配字串} |
Start back from scratch match, delete the line with the longest matching string of data |
${变量名%匹配字串} |
Matches start from the tail forward, delete data in line with the shortest matching string |
${变量名%%匹配字串} |
Matches start from the tail forward, delete the line with the longest matching string of data |
${变量名/旧的字串/新的字串} |
The first string in line with the old string is replaced with a new string |
${变量名//旧的字串/新的字串} |
We will comply with all the old string |
Variables Delete: You can use unset
the command to delete an environment variable
File extension | Explanation |
---|---|
*.zip |
packaged compressed zip file |
*.rar |
rar file compression program |
*.7z |
7zip file compression program |
*.tar |
tar packaged, uncompressed file |
*.gz |
the gzip (GNU zip) compressed files |
*.xz |
xz compressed program files |
*.bz2 |
program bzip2 compressed file |
*.tar.gz |
packaged tar, gzip file compression program |
*.tar.xz |
tar package, xz compressed program files |
*tar.bz2 |
tar package, bzip2 compressed program files |
*.tar.7z |
tar package, 7z file compression program |
- zip:
- Packaging: zip something.zip something (catalog please add -r parameter)
- Unpack: unzip something.zip
- Specify the path: -d parameter
- taking:
- 打包:tar -cf something.tar something
- 解包:tar -xf something.tar
- Specify the path: -C parameter