Preview raw command passed to shell and python/shell mixing #10111

Open
grmpyninja opened this Issue Dec 30, 2016 · 1 comment

Projects

None yet

2 participants

@grmpyninja

Is there a way to preview a raw command which is passed to shell for its execution?

I wanted to execute the following small piece of code

x = "aaaa bbb"
!echo "$x" | awk '{print $1}'

but apparently it simply doesn't work. I've figured out that the working code should look like this

x = "aaaa bbb"
!echo "{x}" | awk '{{print $$1}}'

but I simply tested multiple variations or quotes, double quotes, brackets and dollar sign. It'd be much easier to set some verbose mode to command executer to see the actual command after it's evaluated by ipython.

Anyway, is it the only way of mixing python and shell parameters? Isn't there a more elegant and more shell-like way of doing it? without all those escape sequences? (additional brackets and dollar). I'd like to copy paste the very same command to shell and get the results instead of escaping everything.

@minrk
Member
minrk commented Jan 2, 2017

A flag to echo the command-to-be-executed would be useful. The method used to format these is get_ipython().var_expand(line), which you can use to see what a command would be:

ip = get_ipython()
ip.var_expand("""
echo "{x}" | awk '{{print $$1}}
'""")

We could implement a more bash-like parsing, which doesn't reach into single-quoted strings. That seems desirable, to me.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment