我能够跑步
ip route get 1.1.1.1 | grep -oP 'src \K\S+'
在bash shell下的Ubuntu上。但是,相同的命令在Mac上失败,并显示以下错误:
macpro:folder user$ ip route get 1.1.1.1 | grep -oP 'src \K\S+'
usage: grep [-abcDEFGHhIiJLlmnOoqRSsUVvwxZ] [-A num] [-B num] [-C[num]]
[-e pattern] [-f file] [--binary-files=value] [--color=when]
[--context[=num]] [--directories=action] [--label] [--line-buffered]
[--null] [pattern] [file ...]
close failed in file object destructor:
sys.excepthook is missing
lost sys.stderr
Grep版本:
macpro:folder user$ grep --version
grep (BSD grep) 2.5.1-FreeBSD
https://explainshell.com/explain?cmd=grep+-oP+%27src+%5CK%5CS%2B%27显示这是--perl-regexp
。
还有其他方法可以在Mac上运行--perl-regexp
吗?
注意:对于ip
命令,我已经安装了iproute2mac
软件包。