The man page bsdgrep(1) says the program won't follow any symbolic links when performing recursive search (with option '-r' or '-R'). But it follows! (try it!) From the man page: -O If -R is specified, follow symbolic links only if they were explicitly listed on the command line. The default is not to follow symbolic links. ... -p If -R is specified, no symbolic links are followed. This is the default. ... -R, -r, --recursive Recursively search subdirectories listed. -S If -R is specified, all symbolic links are followed. The default is not to follow symbolic links. This seems indicating that the option '-p' was the default, however the actual default was '-S', according to the source code (https://svnweb.freebsd.org/base/head/usr.bin/grep/grep.c?revision=334806&view=markup#l126).
Created attachment 204352 [details] bsdgrep-fix-manpage.diff
Created attachment 204353 [details] bsdgrep-fix-program.diff
The attached 2 patches could fix the program or the man page.
It seems that the -p option does not work in bsdgrep. How to reproduce: date > date ln -s date symlink # two results expected grep -r . ./date:Mon Apr 29 08:21:22 UTC 2024 ./symlink:Mon Apr 29 08:21:22 UTC 2024 # one result expected grep -pr . ./date:Mon Apr 29 08:21:22 UTC 2024 ./symlink:Mon Apr 29 08:21:22 UTC 2024 # gnu grep works fine, two hits for -R and one for -r options ggrep -R . date:Mon Apr 29 08:21:22 UTC 2024 symlink:Mon Apr 29 08:21:22 UTC 2024 ggrep -r . date:Mon Apr 29 08:21:22 UTC 2024
> It seems that the -p option does not work in bsdgrep By digging futher into the source code, it appears that bsdgrep(1) simply translates its 'LINK_SKIP' for '-p' into 'FTS_PHYSICAL' flag for fts_open(3); after that it didn't have any special handling for symbolic links. Thus for any symbolic link found by fts_read(3) will be followed in function 'procfile'. It should have cases for 'FTS_SL' and 'FTS_SLNONE' to filter out symbolic links in case of 'LINK_SKIP', in this 'switch': https://cgit.freebsd.org/src/tree/usr.bin/grep/util.c?id=e116e040f3091eca914a06dcd0bdd9f1aea23add#n155