在jupyter笔记本中使用此单元格运行正常:
!echo "one two tree"|egrep --color "t[w,r](o|e)"
return(如预期):onetwo tree
当此单元格输入:
!echo "one two tree"|egrep --color "t[w,r](o|e){1,2}"
在木星上什么也没有返回?!
期望返回值:12树
我尝试转义大括号
!echo "one two tree"|egrep --color "t[w,r](o|e){1,2}"
仍然没有返回
问题是您使用的大括号会导致字符串内部的变量展开:
因此,要使大括号成为文字,需要对它们进行双引号:bang后的行可以调用底层shell中安装的任何程序,支持
$variable
或{variable}
形式的变量展开。
egrep "t[wr](o|e){{1,2}}"