^ (插入符号) 在solaris (bourne?) sh 中的特殊含义? [英] special meaning of ^ (caret) in solaris (bourne?) sh?

查看:53
本文介绍了^ (插入符号) 在solaris (bourne?) sh 中的特殊含义?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Solaris 上,我似乎需要单引号匹配行首"表达式:

On Solaris, it appears I need to single quote 'a match the beginning of line' expression:

 > sh
 $ echo offset 0.000000 2>&1 | grep ^offset | tail -1
 offset: not found
 $ Usage:        grep [-c|-l|-q] [-bhinsvwx] pattern_list [file ...]
         grep [-c|-l|-q] [-bhinsvwx] [-e pattern_list]... [-f pattern_file]... [file...]
         grep -E [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
         grep -E [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]
         grep -F [-c|-l|-q] [-bhinsvx] pattern_list [file ...]
         grep -F [-c|-l|-q] [-bhinsvx] [-e pattern_list]... [-f pattern_file]... [file...]

我可以通过单引号正则表达式轻松解决这个问题:

I can fix this easily enough by single quoting the regex:

 > sh
 $ echo offset 0.000000 2>&1 | grep '^offset'| tail -1
 offset 0.000000

我在自己使用 bash 的命令行中没有看到这一点,但它显示在脚本中,例如使用 system() 的 perl 脚本.

I don't see this in my own command line where I'm using bash, but it shows up in scripts, such as a perl script that uses system().

默认的 Solaris shell 是 Bourne shell 吗?^(脱字符号)在默认 Solaris shell 的 shell 语言中还有什么其他含义?

Is that default Solaris shell the Bourne shell? What additional meaning does ^ (caret) have in the shell language for the default Solaris shell?

推荐答案

我相信 bourne shell 中的^"被允许作为|"的向后兼容版本/等价物字符.

I believe '^' in bourne shell was allowed as a backwards compatible version/equivalent of the '|' char.

你所看到的信息似乎支持这种解释.

And the message that your seeing would seems to support that interpretation.

要确认,请制作一个测试脚本 offset ,它只打印必须偏移"以查看.

To confirm, make a test script offset that just prints 'got to offset' to see.

(向后兼容在这个 ol' SunOS3 编码器的 /dev/null 中丢失的东西;-) )

(Backwards compatible to what is lost in this ol' SunOS3 coder's /dev/null ;-) )

IHTH.

这篇关于^ (插入符号) 在solaris (bourne?) sh 中的特殊含义?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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