有人知道在ubuntu 19.10中问号不匹配的原因是什么吗

  • 本文关键字:不匹配 是什么 ubuntu bash grep
  • 更新时间 :
  • 英文 :


当我在globbing模式中使用句点(.(时,它成功地匹配了这组地址:

~$ ip addr show | grep i.et
inet 127.0.0.1/8 scope host lo
inet6 ::1/128 scope host 
inet 192.168.1.101/24 brd 192.168.1.255 scope global dynamic noprefixroute wlp3s0
inet6 fe80::c705:4836:6aa7:d321/64 scope link noprefixroutet

同时,有问题标记的版本什么都不匹配:

~$ ip addr show | grep i?et

有什么想法吗?

Grep的模式是正则表达式。您尝试使用的问号是Bash的globbing(模式匹配(的一部分。

使用globbing的示例:

ls -1d /proc/191?

退货:

/proc/1910
/proc/1913
/proc/1914
/proc/1915
/proc/1916
/proc/1918
/proc/1919

现在使用grep的正则表达式(regex(:

ls -1 /proc | grep '191.'

退货:

1910
1913
1914
1915
1916
1918
1919

希望这有助于澄清混乱。

最新更新