|
38 | 38 | "The magic happens with the exclamation point: anything appearing after ``!`` on a line will be executed not by the Python kernel, but by the system command-line.\n",
|
39 | 39 | "\n",
|
40 | 40 | "The following assumes you're on a Unix-like system, such as Linux or Mac OSX.\n",
|
41 |
| - "Some of the examples that follow will fail on Windows, which uses a different type of shell by default (though with the 2016 announcement of native Bash shells on Windows, soon this may no longer be an issue!).\n", |
| 41 | + "Some of the examples that follow will fail on Windows, which uses a different type of shell by default, though if you use the *Windows Subsystem for Linux* the examples here should run correctly.\n", |
42 | 42 | "If you're unfamiliar with shell commands, I'd suggest reviewing the [Shell Tutorial](http://swcarpentry.github.io/shell-novice/) put together by the always excellent Software Carpentry Foundation."
|
43 | 43 | ]
|
44 | 44 | },
|
|
52 | 52 | "The shell is a way to interact textually with your computer.\n",
|
53 | 53 | "Ever since the mid 1980s, when Microsoft and Apple introduced the first versions of their now ubiquitous graphical operating systems, most computer users have interacted with their operating system through familiar clicking of menus and drag-and-drop movements.\n",
|
54 | 54 | "But operating systems existed long before these graphical user interfaces, and were primarily controlled through sequences of text input: at the prompt, the user would type a command, and the computer would do what the user told it to.\n",
|
55 |
| - "Those early prompt systems are the precursors of the shells and terminals that most active data scientists still use today.\n", |
| 55 | + "Those early prompt systems are the precursors of the shells and terminals that most data scientists still use today.\n", |
56 | 56 | "\n",
|
57 | 57 | "Someone unfamiliar with the shell might ask why you would bother with this, when many results can be accomplished by simply clicking on icons and menus.\n",
|
58 | 58 | "A shell user might reply with another question: why hunt icons and click menus when you can accomplish things much more easily by typing?\n",
|
59 |
| - "While it might sound like a typical tech preference impasse, when moving beyond basic tasks it quickly becomes clear that the shell offers much more control of advanced tasks, though admittedly the learning curve can intimidate the average computer user.\n", |
| 59 | + "While it might sound like a typical tech preference impasse, when moving beyond basic tasks it quickly becomes clear that the shell offers much more control of advanced tasks, though admittedly the learning curve can be intimidating.\n", |
60 | 60 | "\n",
|
61 | 61 | "As an example, here is a sample of a Linux/OSX shell session where a user explores, creates, and modifies directories and files on their system (``osx:~ $`` is the prompt, and everything after the ``$`` sign is the typed command; text that is preceded by a ``#`` is meant just as description, rather than something you would actually type in):\n",
|
62 | 62 | "\n",
|
|
90 | 90 | "```\n",
|
91 | 91 | "\n",
|
92 | 92 | "Notice that all of this is just a compact way to do familiar operations (navigating a directory structure, creating a directory, moving a file, etc.) by typing commands rather than clicking icons and menus.\n",
|
93 |
| - "Note that with just a few commands (``pwd``, ``ls``, ``cd``, ``mkdir``, and ``cp``) you can do many of the most common file operations.\n", |
| 93 | + "With just a few commands (``pwd``, ``ls``, ``cd``, ``mkdir``, and ``cp``) you can do many of the most common file operations.\n", |
94 | 94 | "It's when you go beyond these basics that the shell approach becomes really powerful."
|
95 | 95 | ]
|
96 | 96 | },
|
|
100 | 100 | "source": [
|
101 | 101 | "## Shell Commands in IPython\n",
|
102 | 102 | "\n",
|
103 |
| - "Any command that works at the command-line can be used in IPython by prefixing it with the ``!`` character.\n", |
| 103 | + "Any standard shell command can be used directly in IPython by prefixing it with the ``!`` character.\n", |
104 | 104 | "For example, the ``ls``, ``pwd``, and ``echo`` commands can be run as follows:\n",
|
105 | 105 | "\n",
|
106 | 106 | "```ipython\n",
|
|
136 | 136 | "['/Users/jakevdp/notebooks/tmp/myproject']\n",
|
137 | 137 | "```\n",
|
138 | 138 | "\n",
|
139 |
| - "Note that these results are not returned as lists, but as a special shell return type defined in IPython:\n", |
| 139 | + "These results are not returned as lists, but as a special shell return type defined in IPython:\n", |
140 | 140 | "\n",
|
141 | 141 | "```ipython\n",
|
142 | 142 | "In [8]: type(directory)\n",
|
|
182 | 182 | "/home/jake/projects/myproject\n",
|
183 | 183 | "```\n",
|
184 | 184 | "\n",
|
185 |
| - "The reason is that shell commands in the notebook are executed in a temporary subshell.\n", |
| 185 | + "The reason is that shell commands in the notebook are executed in a temporary subshell that does not maintain state from command to command.\n", |
186 | 186 | "If you'd like to change the working directory in a more enduring way, you can use the ``%cd`` magic command:\n",
|
187 | 187 | "\n",
|
188 | 188 | "```ipython\n",
|
|
197 | 197 | "/home/jake/projects/myproject\n",
|
198 | 198 | "```\n",
|
199 | 199 | "\n",
|
200 |
| - "This is known as an ``automagic`` function, and this behavior can be toggled with the ``%automagic`` magic function.\n", |
| 200 | + "This is known as an ``automagic`` function, and the ability to execute such commands without an explicit `%` can be toggled with the ``%automagic`` magic function.\n", |
201 | 201 | "\n",
|
202 | 202 | "Besides ``%cd``, other available shell-like magic functions are ``%cat``, ``%cp``, ``%env``, ``%ls``, ``%man``, ``%mkdir``, ``%more``, ``%mv``, ``%pwd``, ``%rm``, and ``%rmdir``, any of which can be used without the ``%`` sign if ``automagic`` is on.\n",
|
203 | 203 | "This makes it so that you can almost treat the IPython prompt as if it's a normal shell:\n",
|
|
216 | 216 | "In [20]: rm -r tmp\n",
|
217 | 217 | "```\n",
|
218 | 218 | "\n",
|
219 |
| - "This access to the shell from within the same terminal window as your Python session means that there is a lot less switching back and forth between interpreter and shell as you write your Python code." |
| 219 | + "This access to the shell from within the same terminal window as your Python session lets you more naturally combine Python and the shell in your workflows with fewer context switches." |
220 | 220 | ]
|
221 | 221 | },
|
222 | 222 | {
|
|
0 commit comments