.bash_profile sed: 1 未在 RE 中定义 [英] .bash_profile sed: 1 not defined in the RE

查看:20
本文介绍了.bash_profile sed: 1 未在 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?

推荐答案

你应该使用 (.*) 而不是 (.*).

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

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 的使用,但它是 没有被POSIX指定,如果你想便携就不能使用它.

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: 1 未在 RE 中定义的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆