-
-
Notifications
You must be signed in to change notification settings - Fork 1k
Gentler introduction to recursion #1515
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
60e2fe7
7e02688
3247952
8ea08ad
27481c7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -93,6 +93,17 @@ The `-R` option to the `ls` command will list all nested subdirectories within a | |||||||||||||||||||||||
| Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the | ||||||||||||||||||||||||
| `project` directory: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| The `-R` option to the `ls` command will list all nested subdirectories within a directory. | ||||||||||||||||||||||||
| `R` in `-R` stands for "Recursive" which refers to the idea that the output of a process | ||||||||||||||||||||||||
| becomes the input of another iteration of that same process. | ||||||||||||||||||||||||
| So in this case, `ls -R` lists the contents of a directory, and for every directory | ||||||||||||||||||||||||
| it finds, it lists the contents of that directory, | ||||||||||||||||||||||||
| and for every directory inside those subdirectories, | ||||||||||||||||||||||||
| it lists the contents, and so on. | ||||||||||||||||||||||||
|
Comment on lines
+96
to
+102
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Perhaps if is changed to to ensure recursive links to the glossary add just before the Keypoints section, see #1510
Suggested change
|
||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Let's use `ls -FR` to recursively list the new directory hierarchy we just created in the | ||||||||||||||||||||||||
| `project` directory: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| $ ls -FR ../project | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
@@ -477,9 +488,12 @@ $ ls quotes.txt thesis/quotations.txt | |||||||||||||||||||||||
| quotes.txt thesis/quotations.txt | ||||||||||||||||||||||||
| ``` | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| We can also copy a directory and all its contents by using the | ||||||||||||||||||||||||
| [recursive](https://en.wikipedia.org/wiki/Recursion) option `-r`, | ||||||||||||||||||||||||
| e.g. to back up a directory: | ||||||||||||||||||||||||
| Just like the recursive (`-R`) option for `ls`, | ||||||||||||||||||||||||
| the `-r` option for `cp` | ||||||||||||||||||||||||
| applies the command not just to the specifed directory, | ||||||||||||||||||||||||
| but to all its contents. | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| As an example, we can use this to back up a directory: | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| ```bash | ||||||||||||||||||||||||
| $ cp -r thesis thesis_backup | ||||||||||||||||||||||||
|
|
||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -160,6 +160,12 @@ so that the shell will not try to expand the `*` wildcard. | |||||||||||||
| : (REPL): A [command-line interface](#command-line-interface) that reads a command from the user, | ||||||||||||||
| executes it, prints the result, and waits for another command. | ||||||||||||||
|
|
||||||||||||||
| [recursive]{#recursive} | ||||||||||||||
| : A recursive precudure is one where one step of the procedure is to apply the procedure itself | ||||||||||||||
| (usually to a different input). | ||||||||||||||
| In the context of shell, it often refers to applying a command to a directory and to all directories | ||||||||||||||
| contained within that directory. | ||||||||||||||
|
Comment on lines
+164
to
+167
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Is context of the shell lesson helpful? Maybe should be added to
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I put this because for all except For this reason, I think the main thing learners need to know is that This "apply to everything inside" is probably novices default way of thinking of commands and the fact that it's not the default for shell commands and |
||||||||||||||
|
|
||||||||||||||
| [redirect]{#redirect} | ||||||||||||||
| : To send a command's output to a file rather than to the screen or another command, | ||||||||||||||
| or equivalently to read a command's input from a file. | ||||||||||||||
|
|
||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe "Recursion" should be in the glossary? This might allow simplifying the paragraph.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree it should be added. I'll add that to this PR. I still think a short inline explanation would be helpful. The instructor will need to verbally explain
-R/-rsomehow so I think coming up with some nice concise and approachable wording will be helpful.