Home > other >  Unexpected result while executing terminal command in Jupyter notebook
Unexpected result while executing terminal command in Jupyter notebook

Time:10-13

Having this cell in the jupyter notebook runs OK:

!echo "one two tree"|egrep --color "t[w,r](o|e)"

return(as expected): one two tree

while this cell input:

!echo "one two tree"|egrep --color "t[w,r](o|e){1,2}"

returns nothing on jupyter?!
expected return: one two tree

I tried escaping curly braces

!echo "one two tree"|egrep --color "t[w,r](o|e)\{1,2\}"

still nothing on the return

CodePudding user response:

The problem is that you are using braces that cause variable expansion inside the string:

The line after the bang can call any program installed in the underlying shell, and support variable expansion in the form of $variable or {variable}.

Hence, to make the braces literal you need to double them:

egrep "t[wr](o|e){{1,2}}"
  • Related