Skip to content

Instantly share code, notes, and snippets.

@workze
Last active March 21, 2020 08:44
Show Gist options
  • Save workze/71c596812a2c19782634e8c9efef6620 to your computer and use it in GitHub Desktop.
Save workze/71c596812a2c19782634e8c9efef6620 to your computer and use it in GitHub Desktop.
shell bash string 字符串 截取 替换
# 替换
${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