在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...]
我可以通过单引用正则表达式来轻松解决这个问题:
> sh
$ echo offset 0.000000 2>&1 | grep '^offset'| tail -1
offset 0.000000
我在我自己的命令行中没有看到这个,我正在使用bash,但它出现在脚本中,例如使用system()的perl脚本。
这个默认的Solaris shell是Bourne shell吗? ^(插入符号)在shell语言中对于默认的Solaris shell有什么额外的含义?
答案 0 :(得分:5)
我相信' ^'在bourne shell中允许作为向后兼容的版本/等同于' |'炭。
你所看到的信息似乎支持这种解释。
要进行确认,请制作一个只打印出来的测试脚本offset
来抵消'看。
(向后兼容此版本的SunOS3编码器/dev/null
中所遗失的内容;-))
IHTH。