Last active
March 21, 2020 08:44
-
-
Save workze/71c596812a2c19782634e8c9efef6620 to your computer and use it in GitHub Desktop.
shell bash string 字符串 截取 替换
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 替换 | |
${string/substring/replacement} | |
${string//substring/replacement} | |
# 提取子串 | |
${string:position:length} | |
# 删除 | |
${string#substring} | |
test='c:/windows/boot.ini' | |
${test#*/} ---> windows/boot.ini | |
# 开头 % 结尾 | |
## 最大匹配 %% 最小匹配 | |
/ 是关键字,需要转义,\/ | |
============================ | |
workspace=$(pwd) # /home/cloudci/workspace/aep-customer/aep_customer_verifyci/config-south-integration | |
workspace_prefix=${workspace%/*} # /home/cloudci/workspace/aep-customer/aep_customer_verifyci | |
prj_integration=${workspace##*/} # config-south-integration | |
prj_name=${prj_integration%-*} # config-south | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment