gpt4 book ai didi

solaris - ^(插入符号)在 solaris(bourne?)sh 中的特殊含义?

转载 作者:行者123 更新时间:2023-12-02 22:24:50 26 4
gpt4 key购买 nike

在 Solaris 上,我似乎需要单引号 'a match the beginning of line' 表达式:

 > 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 吗? ^(插入符号)在默认 Solaris shell 的 shell 语言中还有什么其他含义?

最佳答案

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

而且您所看到的信息似乎支持这种解释。

为了确认,制作一个测试脚本 offset,它只打印 'got to offset' 以供查看。

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

IHTH.

关于solaris - ^(插入符号)在 solaris(bourne?)sh 中的特殊含义?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13125406/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com