Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/bash/15.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
从字符串bash中删除一个单词_Bash - Fatal编程技术网

从字符串bash中删除一个单词

从字符串bash中删除一个单词,bash,Bash,我有绳子 file="this-is-a-{test}file" 我想从这个字符串中删除{test}。 我曾经 echo $file | sed 's/[{][^}]*//' 但这件事回报了我 this-is-a-}file 如何将}也删除 谢谢您可以将sed与正确的正则表达式一起使用: s="this-is-a-{test}file" sed 's/{[^}]*}//' <<< "$s" this-is-a-file s=“this-is-a-{test}文件”

我有绳子

file="this-is-a-{test}file" 
我想从这个字符串中删除
{test}
。 我曾经

echo $file | sed 's/[{][^}]*//'  
但这件事回报了我

this-is-a-}file
如何将
}
也删除


谢谢

您可以将
sed
与正确的正则表达式一起使用:

s="this-is-a-{test}file"
sed 's/{[^}]*}//' <<< "$s"
this-is-a-file
s=“this-is-a-{test}文件”

sed的/{[^}]*}/'也可以使用此bash only oneliner作为替代:

s="this-is-a-{test}file"
echo ${s/\{test\}/}

@CiprianVintea表示“感谢”的首选方式是接受对您提出的任何问题最有帮助的答案(点击绿色复选标记)(这也会增加您的声誉),并投票选出有帮助的答案(如果您有15+的声誉)。请阅读答案,祝你好运。
s="this-is-a-{test}file"
echo ${s/\{test\}/}