在Solaris上,似乎我需要单引号"匹配行的开头"表达式:
> 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...]
Run Code Online (Sandbox Code Playgroud)
我可以通过单引用正则表达式来轻松解决这个问题:
> sh
$ echo offset 0.000000 2>&1 | grep '^offset'| tail -1
offset 0.000000
Run Code Online (Sandbox Code Playgroud)
我在我自己的命令行中没有看到这个,我正在使用bash,但它出现在脚本中,例如使用system()的perl脚本.
这是默认的Solaris shell Bourne shell吗?^(插入符号)在shell语言中对于默认的Solaris shell有什么额外的含义?
我相信bourne shell中的'^'被允许作为向后兼容的版本/相当于'|' 焦炭.
而你所看到的信息似乎支持这种解释.
要确认,请创建一个offset只打印'got to offset' 的测试脚本.
(向后兼容这个'SunOS3编码器'中丢失的内容/dev/null;-))
IHTH.