Linux Bash Shell string truncation, bashshell
#! /Bin/bash
# No space is allowed on both sides of the equal sign when the variable is assigned a value. Otherwise, the command does not exist.
# Run shell scripts in two ways
#1. As the interpretation parameter/bin/sh test. sh; 2. As the executable file chmod + x./test. sh
Blog_url = 'HTTP: // www.cnblogs.com/big#/p/7535900.html'
#1. # intercept the number, and delete the part starting from 0 to the First Matching condition ('//') from left to right. Retain the remaining part.
Echo $ {blog_url #*//}
# The running result is as follows: www.cnblogs.com/big#/p/7535900.html
#2, ## # truncate, delete from left to right from 0 to the last matching condition ('/'), and retain the remaining part
Echo $ {blog_url ##*/}
# The running result is as follows: 7535900.html
#3. truncate "%", and delete the part from # blog_url to the First Matching condition ('/') from the right to the left, and retain the remaining part.
Echo $ {blog_url % /*}
# Run the result of the following http://www.cnblogs.com/Bighua/p
#4. Intercept the % number, and delete the part starting from # blog_url to the last matching condition ('/') from the right to the left. The remaining part is retained.
Echo $ {blog_url % /*}
# The running result is as follows:
#5. The number of characters on the left
Echo $ {blog_url: 0: 7}
# The running result is as follows: http ://
#6. Start from the number of characters on the left to the end
Echo $ {blog_url: 7}
# The running result is as follows: www.cnblogs.com/big#/p/7535900.html
#7. The number of characters starting from the right is used as the starting point, and the number of characters from left to right is truncated.
Echo $ {blog_url: 0-7:2}
# The running result is as follows: 00
#8. Start from the right to the end
Echo $ {blog_url: 0-4}
# Running result html