1

I would like to add a bash magic cell with both a environment variable and a python variable, like this:

!echo "{1+1}" "$HOME" 

Expecting it to print:

2 /home/ec2-user

However, this does not evaluate the python expression, output is:

{1+1} /home/ec2-user

Removing the environment variable makes the python expression work:

!echo "{1+1}" "HOME" 
2 HOME

What would be the correct syntax for printing both variables?

1 Answer 1

1

https://ipython.readthedocs.io/en/stable/interactive/reference.html#system-shell-access

The docs has an example with $$HOME.

In [27]: !echo $HOME
/home/paul
In [28]: !echo $$HOME
/home/paul
In [29]: !echo {i+3} $$HOME
5 /home/paul

Looks like $var can be parsed as either a substitution from a local variable, or pass it on the shell for its evaluation. $$HOME seems to force the shell use. But it's not obvious from the documentation how it handles those details.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.