Lucretiel
Lucretiel

Reputation: 3324

IPython !! not working

So I've starting using IPython on my Mac. The !! operator, which is supposed to execute a shell command and get the output as useful data, is generating syntax errors. It appears to be just interpreting it as (! (!ls)), and spitting out !ls: command not found. I can't google exclamation marks and I didn't know where else to turn

Upvotes: 2

Views: 1311

Answers (2)

Keith
Keith

Reputation: 43024

The !! shortcut is an alias for the %sx ls magic command. This was introduced recently so your version may not have that functionality.

Upvotes: 2

DSM
DSM

Reputation: 352979

I think you probably only want a single exclamation mark [docs], at least if you want to do anything with the output. For example:

localhost-2:tmp $ ipython
Python 2.7.2 (v2.7.2:8527427914a2, Jun 11 2011, 15:22:34) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

In [1]: !ls
a.txt

In [2]: z = !ls

In [3]: z
Out[3]: ['a.txt']

In [4]: !!ls
Out[4]: ['a.txt']

but (which is what I'm assuming you're seeing)

In [10]: z = !!ls

In [11]: z
Out[11]: ['/bin/sh: !ls: command not found']

You can type %sx? for more information about what !!ls actually does.

Upvotes: 5

Related Questions