从Bash中的字符串中删除固定的前缀/后缀 [英] Remove a fixed prefix/suffix from a string in Bash
本文介绍了从Bash中的字符串中删除固定的前缀/后缀的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在我的bash
脚本中,我有一个字符串及其前缀/后缀.我需要从原始字符串中删除前缀/后缀.
In my bash
script I have a string and its prefix/suffix. I need to remove the prefix/suffix from the original string.
例如,假设我具有以下值:
For example, let's say I have the following values:
string="hello-world"
prefix="hell"
suffix="ld"
如何获得以下结果?
result="o-wor"
推荐答案
$ foo=${string#"$prefix"}
$ foo=${foo%"$suffix"}
$ echo "${foo}"
o-wor
这篇关于从Bash中的字符串中删除固定的前缀/后缀的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文