Shell script variables and string interception

Source: Internet
Author: User

Variable Description:
$$ The shell itself PID (ProcessID)
$! PID of the Shell's last running background process
$? End code of last Run command (return value)
$-flag at a glance using the SET command
$* all parameter lists. such as "$*" in the Case of "" ", in the form of" $ $ ... $n "output all parameters.
[email protected] all parameter lists. such as "[email protected]" with "" "in the case, with" $1″ "$2″ ... All parameters are output in the form "$n".
$# Number of arguments added to the shell
the file name of the shell itself
$1~ $n Each parameter value added to the shell. $ $ is the 1th parameter, the $ $ is the 2nd parameter ...

string interception:
string interception of Linux is useful. There are eight ways.
Suppose there is a variable var=http://www.sharelinux.com/index.html
1. # Intercept, delete the left character, leave the right character.
Echo ${var#*//}
where Var is the variable name and the # is an operator, *//indicates that the first//number and all characters on the left are deleted from the left.
Delete http: //
The result is: www.sharelinux.com/index.html
2. # # Intercept, delete the left character and leave the right character.
Echo ${var##*/}
##*/indicates that the last (rightmost) one/number and all characters to the left are deleted from the left.
that is, delete http://www.sharelinux.com/
The result is index.html .
3.% Intercept, delete right character, leave left character
Echo ${var%/*}
%/* indicates that the first/second and right characters are deleted from the right.
The result is: http://www.sharelinux.com
4. The percent number intercept, delete the right character, leave the left character
Echo ${var%%/*}
%%/* indicates that the last (leftmost) one/number and right character are deleted from the right.
The result is: http:
5. Start with the first few characters on the left and the number of characters
Echo ${var:0:5}
0 represents the first character on the left and 5 indicates the total number of characters.
The result is: http:
6. Start with the first few characters on the left and continue to the end.
Echo ${var:7}
7 means that the 8th character on the left begins, until the end.
The result is: www.sharelinux.com/index.html
7. Start with the first few characters on the right and the number of characters
Echo ${var:0-7:3}
0-7 means that the seventh character starts at the right, and 3 indicates the number of characters.
The result is: 123
8. Start with the first few characters on the right and continue to the end.
Echo ${var:0-7}
The expression starts at the seventh character on the right and continues to the end.
The result is: index.html
Note: (The first character on the left is denoted by 0, and the first character on the right is denoted by 0-1)

This article is from the "Sanctuary of Calm" blog, please make sure to keep this source http://masters.blog.51cto.com/6516495/1642200

Shell script variables and string interception

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.