所以当我在Fedora运行这个时,我看到这个:
$ ls hmm_data/indivA12_AATAAG/refs/par1/ 2R-orths.alleles 2R-ref.alleles $ ls hmm_data/indivA12_AATAAG/refs/par1/ | grep -F '-ref.alleles' 2R-ref.alleles
但是,当我在Ubuntu上运行(相同的数据),我没有从grep得到任何结果:
$ ls hmm_data/indivA12_AATAAG/refs/par1/ 2R-orths.alleles 2R-ref.alleles $ ls hmm_data/indivA12_AATAAG/refs/par1/ | grep -F '-ref.alleles'
任何想法可能会发生什么? 我怎么能想出在两个系统上都一样的东西?
grep -F '-ref.alleles'
相当于:
grep -F -ref.alleles
(撇号之间的字符都不是shell元字符,所以引用它们没有任何作用。)
这又相当于:
grep -F -r -e f.alleles
通过正常的parsing-前缀选项。 -e选项需要一个参数,但-F和-r不需要。
由于您没有指定任何文件到grep,默认的行为是行事stdin …除了-r选项没有意义,所以它默认为search. (当前目录),而是recursion地忽略stdin。 在一些版本中。
您需要使用-- “no more options”指示符才能开始使用正则expression式
grep -F -- -ref.alleles
我跟踪了没有文件参数的-r行为改变的地方。 它是在2012年3月2日发布的2.11版。 请参阅发行公告。
影响行为的git提交是这个和这个 。
如果你在两台机器上运行grep --version ,我相信你会发现其中一个是在2.11的错误的一面
领先-是问题。 要获得相同的结果添加-- :
grep -F -- '-ref.alleles'
从man bash :
A -- signals the end of options and disables further option processing. Any arguments after the -- are treated as filenames and arguments.
如果你的grep命令有任何别名覆盖它的行为,请检查.bashrc。 也许这是问题。 也尝试没有“-F”参数的grep。