Skip to content

Commit 75160a7

Browse files
committedMar 11, 2021
update 01.05
1 parent 8e6ddff commit 75160a7

File tree

2 files changed

+18
-18
lines changed

2 files changed

+18
-18
lines changed
 

‎notebooks_v2/01.05-IPython-And-Shell-Commands.ipynb

+9-9
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@
3838
"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",
3939
"\n",
4040
"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",
4242
"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."
4343
]
4444
},
@@ -52,11 +52,11 @@
5252
"The shell is a way to interact textually with your computer.\n",
5353
"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",
5454
"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",
5656
"\n",
5757
"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",
5858
"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",
6060
"\n",
6161
"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",
6262
"\n",
@@ -90,7 +90,7 @@
9090
"```\n",
9191
"\n",
9292
"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",
9494
"It's when you go beyond these basics that the shell approach becomes really powerful."
9595
]
9696
},
@@ -100,7 +100,7 @@
100100
"source": [
101101
"## Shell Commands in IPython\n",
102102
"\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",
104104
"For example, the ``ls``, ``pwd``, and ``echo`` commands can be run as follows:\n",
105105
"\n",
106106
"```ipython\n",
@@ -136,7 +136,7 @@
136136
"['/Users/jakevdp/notebooks/tmp/myproject']\n",
137137
"```\n",
138138
"\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",
140140
"\n",
141141
"```ipython\n",
142142
"In [8]: type(directory)\n",
@@ -182,7 +182,7 @@
182182
"/home/jake/projects/myproject\n",
183183
"```\n",
184184
"\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",
186186
"If you'd like to change the working directory in a more enduring way, you can use the ``%cd`` magic command:\n",
187187
"\n",
188188
"```ipython\n",
@@ -197,7 +197,7 @@
197197
"/home/jake/projects/myproject\n",
198198
"```\n",
199199
"\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",
201201
"\n",
202202
"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",
203203
"This makes it so that you can almost treat the IPython prompt as if it's a normal shell:\n",
@@ -216,7 +216,7 @@
216216
"In [20]: rm -r tmp\n",
217217
"```\n",
218218
"\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."
220220
]
221221
},
222222
{

‎notebooks_v2/01.05-IPython-And-Shell-Commands.md

+9-9
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ IPython bridges this gap, and gives you a syntax for executing shell commands di
3636
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.
3737

3838
The following assumes you're on a Unix-like system, such as Linux or Mac OSX.
39-
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!).
39+
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.
4040
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.
4141

4242
<!-- #region -->
@@ -46,11 +46,11 @@ A full intro to using the shell/terminal/command-line is well beyond the scope o
4646
The shell is a way to interact textually with your computer.
4747
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.
4848
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.
49-
Those early prompt systems are the precursors of the shells and terminals that most active data scientists still use today.
49+
Those early prompt systems are the precursors of the shells and terminals that most data scientists still use today.
5050

5151
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.
5252
A shell user might reply with another question: why hunt icons and click menus when you can accomplish things much more easily by typing?
53-
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.
53+
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.
5454

5555
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):
5656

@@ -84,13 +84,13 @@ myproject.txt
8484
```
8585

8686
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.
87-
Note that with just a few commands (``pwd``, ``ls``, ``cd``, ``mkdir``, and ``cp``) you can do many of the most common file operations.
87+
With just a few commands (``pwd``, ``ls``, ``cd``, ``mkdir``, and ``cp``) you can do many of the most common file operations.
8888
It's when you go beyond these basics that the shell approach becomes really powerful.
8989
<!-- #endregion -->
9090

9191
## Shell Commands in IPython
9292

93-
Any command that works at the command-line can be used in IPython by prefixing it with the ``!`` character.
93+
Any standard shell command can be used directly in IPython by prefixing it with the ``!`` character.
9494
For example, the ``ls``, ``pwd``, and ``echo`` commands can be run as follows:
9595

9696
```ipython
@@ -122,7 +122,7 @@ In [7]: print(directory)
122122
['/Users/jakevdp/notebooks/tmp/myproject']
123123
```
124124

125-
Note that these results are not returned as lists, but as a special shell return type defined in IPython:
125+
These results are not returned as lists, but as a special shell return type defined in IPython:
126126

127127
```ipython
128128
In [8]: type(directory)
@@ -160,7 +160,7 @@ In [13]: !pwd
160160
/home/jake/projects/myproject
161161
```
162162

163-
The reason is that shell commands in the notebook are executed in a temporary subshell.
163+
The reason is that shell commands in the notebook are executed in a temporary subshell that does not maintain state from command to command.
164164
If you'd like to change the working directory in a more enduring way, you can use the ``%cd`` magic command:
165165

166166
```ipython
@@ -175,7 +175,7 @@ In [15]: cd myproject
175175
/home/jake/projects/myproject
176176
```
177177

178-
This is known as an ``automagic`` function, and this behavior can be toggled with the ``%automagic`` magic function.
178+
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.
179179

180180
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.
181181
This makes it so that you can almost treat the IPython prompt as if it's a normal shell:
@@ -194,7 +194,7 @@ myproject.txt
194194
In [20]: rm -r tmp
195195
```
196196

197-
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.
197+
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.
198198

199199

200200
<!--NAVIGATION-->

0 commit comments

Comments
 (0)
Failed to load comments.