grep behaving differently on Fedora vs Ubuntu

Solution 1:

grep -F '-ref.alleles'

is equivalent to:

grep -F -ref.alleles

(none of the characters between the apostrophes are shell metacharacters, so quoting them has no effect.)

This is in turn equivalent to:

grep -F -r -e f.alleles

by normal parsing of - prefixed options. The -e option takes an argument, but -F and -r don't.

Since you didn't specify any files to grep, the default behavior is to act on stdin... except that the -r option makes no sense so it defaults to searching . (the current directory) recursively instead and ignores stdin. In some versions.

You need to use the -- "no more options" indicator before a regexp that starts with - as in

grep -F -- -ref.alleles

I tracked down the point where the behavior of -r with no file arguments changed. It was in version 2.11, released March 2, 2012. See the release announcement.

The git commits which affected the behavior are this one and this one.

If you run grep --version on your two machines, I'm sure you'll find that one of them is on the wrong side of 2.11

Solution 2:

The leading - is the problem. To get same results add --:

grep -F -- '-ref.alleles'

From man bash:

A -- signals the end of options and disables further option
processing. Any arguments after the -- are treated as filenames
and arguments.