[chao@localhost ~]$ var1="I love you, Do you love me" [chao@localhost ~]$ echo $var1 I love you, Do you love me # 头部匹配删除 [chao@localhost ~]$ var2=${var1#*ov} [chao@localhost ~]$ echo $var2 e you, Do you love me [chao@localhost ~]$ var3=${var1##*ov} # 贪婪模式 [chao@localhost ~]$ echo $var3 e me # 尾部匹配删除 [chao@localhost ~]$ var4=${var1%ov*} [chao@localhost ~]$ echo $var4 I love you, Do you l [chao@localhost ~]$ var5=${var1%%ov*} # 贪婪模式 [chao@localhost ~]$ echo $var5 I l # 替换 [chao@localhost ~]$ var6=${var1/love/hate} [chao@localhost ~]$ echo $var6 I hate you, Do you love me [chao@localhost ~]$ var7=${var1//love/hate} [chao@localhost ~]$ echo $var7 I hate you, Do you hate me