I've got OSX 10.8.4 on MacBook Air and your example doesn't crash by default, but only when adding --color
parameter.
Explanation
This crash usually happens when you're mixing wilcard (asterisk sign) with the terminal colours and this is the software bug.
Also check another simpler example:
echo 'abc*' | grep --color=auto -e ".*" -e a
Here it seems that --color=auto
makes the difference (without it or setting to never
, then it doesn't crash).
So I assume that your grep is using colors in terminal by default.
Solution
Make sure that your grep is not an alias to the grep with colors enabled, or the colors are not enabled by default.
You can always try to run grep with --color=never
.
For permanent solution, I've reported the bug report:
http://www.freebsd.org/cgi/query-pr.cgi?pr=181263
so the issue can be fixed in the software it-self.
If you'd like to access more detailed log of your crash, go to Console, Show Log List and find the crash log under User Diagnostic Reports.
E.g.:
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 libsystem_c.dylib 0x00007fff8a8da1b3 memchr + 15
1 libsystem_c.dylib 0x00007fff8a90b45a __sfvwrite + 578
2 libsystem_c.dylib 0x00007fff8a90b861 fwrite + 114
3 grep 0x000000010a4a3138 0x10a4a0000 + 12600
4 grep 0x000000010a4a2988 0x10a4a0000 + 10632
5 grep 0x000000010a4a1c28 0x10a4a0000 + 7208
6 libdyld.dylib 0x00007fff8daf77e1 start + 1
Here is some more detailed explanation about the crash:
A quick test
$ env -i bsdgrep -Fi without_nls usr.bin/grep/grep.c
$ env -i gnugrep -Fi without_nls usr.bin/grep/grep.c
#ifndef WITHOUT_NLS
#ifndef WITHOUT_NLS
#ifndef WITHOUT_NLS
shows that bsd fgrep already fails to ignore case. And if you throw
a few more options to the mix it'd crash, e.g.
$ env -i LC_CTYPE=en_US.UTF-8 TERM=xterm bsdgrep --color -Fir without_nls usr.bin/grep/
[...]
Program received signal SIGSEGV, Segmentation fault.
0x0000000801007ff2 in memchr (s=0x61167a, c=10, n=18446744073707490297) at /usr/src/lib/libc/string/memchr.c:48
48 if (*p++ == (unsigned char)c)
(gdb) bt
#0 0x0000000801007ff2 in memchr (s=0x61167a, c=10, n=18446744073707490297) at /usr/src/lib/libc/string/memchr.c:48
#1 0x0000000801007b03 in __sfvwrite (fp=0x801247770, uio=0x7fffffffd8f0) at /usr/src/lib/libc/stdio/fvwrite.c:170
#2 0x0000000801007698 in fwrite (buf=0x608c03, size=18446744073709551606, count=1, fp=0x801247770)
at /usr/src/lib/libc/stdio/fwrite.c:95
#3 0x0000000000405498 in printline (line=0x7fffffffdb70, sep=58, matches=0x7fffffffd990, m=9)
at /usr/src/usr.bin/grep/util.c:500
#4 0x0000000000404f51 in procline (l=0x7fffffffdb70, nottext=0) at /usr/src/usr.bin/grep/util.c:381
#5 0x000000000040489f in procfile (fn=0x80140b600 "usr.bin/grep/nls/es_ES.ISO8859-1.msg") at /usr/src/usr.bin/grep/util.c:239
#6 0x00000000004044d7 in grep_tree (argv=0x7fffffffdd30) at /usr/src/usr.bin/grep/util.c:163
#7 0x0000000000403ea9 in main (argc=5, argv=0x7fffffffdd10) at /usr/src/usr.bin/grep/grep.c:689
Source: http://lists.freebsd.org/pipermail/freebsd-current/2011-August/026502.html
Also it seems that there are different grep binaries on different OSX even with the same version:
$ grep --v
grep (BSD grep) 2.5.1-FreeBSD
$ shasum /usr/bin/grep
350ee11e1868e18c9707ea7035184a114f40badf /usr/bin/grep
$ codesign -dvvv /usr/bin/grep
Executable=/usr/bin/grep
Identifier=com.apple.zgrep
Format=Mach-O thin (x86_64)
CodeDirectory v=20100 size=224 flags=0x0(none) hashes=6+2 location=embedded
Hash type=sha1 size=20
CDHash=1537b3ed49878d5d18482859a37318164a2a40f1
Signature size=4064
Authority=Software Signing
Authority=Apple Code Signing Certification Authority
Authority=Apple Root CA
Info.plist=not bound
Sealed Resources=none
Internal requirements count=2 size=176