.bash_profile sed:RE中未定义\ 1 [英] .bash_profile sed: \1 not defined in the RE
问题描述
我必须在OS X 10.9上设置本地Web开发环境并安装Homebrew.本指南的下一步告诉我使用以下命令向~/.bash_profile
添加逻辑:
I've to set up a local web development environment on my OS X 10.9 and installed Homebrew. Next step in my guide tells me to add logic to my ~/.bash_profile
with the following command:
echo "export PATH=\$(echo \$PATH | sed 's|/usr/local/bin||; s|/usr/local/sbin||; s|::|:|; s|^:||; s|(.*)|/usr/local/bin:/usr/local/sbin:\1|')" >> ~/.bash_profile && source ~/.bash_profile
在终端中输入时,我得到:
When I enter it in the terminal I get:
sed: 1: "s|/usr/local/bin||; s|/ ...": \1 not defined in the RE
应该将export PATH=/usr/local/bin:/usr/local/sbin:$PATH
写入我的.bash_profile
吗?为什么我会收到该错误?
Is it export PATH=/usr/local/bin:/usr/local/sbin:$PATH
that should be written to my .bash_profile
? And why do I get that error?
推荐答案
您应使用\(.*\)
而不是(.*)
.
sed
默认情况下使用基本正则表达式(BRE),它使用\(
和\)
进行组捕获,而不仅仅是扩展正则表达式(ERE)中使用的(
和)
.由于您的表达式使用的是(.*)
而不是\(.*\)
,因此不会将其识别为组捕获,因此不会捕获任何内容以供\1
使用.
sed
uses Basic Regular Expressions (BRE) by default, which uses \(
and \)
for group capturing, not just (
and )
as used in Extended Regular Expressions (ERE). Since your expression used (.*)
instead of \(.*\)
, it is not recognised as a group capture, and thus nothing is captured for use with \1
.
某些sed
实现(例如GNU和BSD提供的实现)确实具有用于指定ERE使用的扩展名,但是它是
Some sed
implementations, such as the ones provided by GNU and BSD, do have an extension for specifying the use of ERE, but it is not specified by POSIX, and you cannot use it if you want to be portable.
这篇关于.bash_profile sed:RE中未定义\ 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!