Files
linux-wiki/content/deepin折腾笔记/第十一章/11.23.md
2021-10-21 14:57:58 +08:00

17 lines
558 B
Markdown
Executable File
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# 11.23 字符串截取
1 以str变量为例str=gmp-6.1.0.tar.bz2
2 echo ${str} |cut -d '-' -f 1 #以 -分隔输出第1列gmp
3 echo ${str%%-*} #以 -分隔最大限度从前面截取字符串gmp
4 echo ${str##*.} #以 .分隔最大限度从后面截取字符串bz2
5 echo ${str:0:3} #从左开始输出3个字符gmp
6 echo ${str:4} #从左面第5个字符开始输出直到结束6.1.0.tar.bz2
7 echo ${str:4:5} #从第5个字符开始输出5个字符6.1.0
8 echo ${str:0-8} #从右开始输出8个字符.tar.bz2