.bash_profile sed: \1 not defined in the RE

白昼怎懂夜的黑 提交于 2019-11-28 18:32:27

问题


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

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?


回答1:


You should use \(.*\) instead of (.*).

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.

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.



来源:https://stackoverflow.com/questions/24717676/bash-profile-sed-1-not-defined-in-the-re

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!