Repository navigation
Add the Messy Downloads concept exercise for quoting #987
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
Merged
glennj
merged 8 commits into
exercism:main
from
glennj:concept-exercise-messy-downloads
Nov 30, 2026
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
465525d
simplifying the quoting concept.
glennj 04fe809
Final adjustments to ensure the exercise practices what's in the docs…
glennj f7685fa
Allow loops to list matching files in messy-downloads
glennj 91ecb9c
Apply batched suggestions from code review
glennj d5c7602
review suggestions
glennj cca211a
configlet generate
glennj cbe4f51
move the "advanced" files
glennj a92af51
instructions link to prior concept
glennj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,27 @@ | ||
| # Advanced Filename Expansion | ||
|
|
||
| (Note this material is for a future concept) | ||
|
|
||
| ## Disable Filename Expansion | ||
|
|
||
| You can use the [`set`][set] command to disable filename expansion. | ||
|
|
||
| ```bash | ||
| echo * # prints a list of files | ||
| set -f # disable filename expansion | ||
| echo * # prints a literal asterisk | ||
| set +f # enable filename expansion | ||
| ``` | ||
|
|
||
| ## Controlling Filename Expansion | ||
|
|
||
| There are several settings for the builtin [`shopt`][shopt] command that control how filename expansion operates. | ||
| A couple of interesting ones are: | ||
|
|
||
| * `shopt -s nocaseglob` -- perform case insensitive matching | ||
| * `shopt -s extglob` -- enable extended patterns | ||
| * `shopt -s nullglob` -- if no files match, replace the pattern with nothing. | ||
| The default behaviour is to leave the pattern in place as a literal string. | ||
|
|
||
| [set]: https://www.gnu.org/software/bash/manual/bash.html#The-Set-Builtin | ||
| [shopt]: https://www.gnu.org/software/bash/manual/bash.html#The-Shopt-Builtin |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,67 @@ | ||
| # Advanced Globbing | ||
|
|
||
| (Note this material is for a future concept) | ||
|
|
||
| ## Character Sets | ||
|
|
||
| There are lots of details about character sets in glob patterns. | ||
|
|
||
| * `[abc]` matches exactly one character that is either an `a` or a `b` or a `c`. | ||
| * to include a literal close bracket in the expression, make it the first character after the opening bracket (after an optional `^`) | ||
| * `[][]` is a character set that will match either a close or an open bracket. | ||
| * or escape it with a backslash: `[[\]]` | ||
| * `[x-y]` matches exactly one character that is in the _range_ from `x` to `y` | ||
| * to include a literal hyphen character in a character set, it must be either the first character after the opening bracket (after an optional `^`) or the last character before the closing bracket. | ||
| * `[-xy]` or `[xy-]` each match exactly one character that is an `-` or a `x` or a `y` | ||
| * or escape it with a backslash: `[x\-y]` | ||
| * multiple ranges can be specified, for example `[0-9A-Fa-f]` matches a hexadecimal digit | ||
| * `[^abc]` matches exactly one character that is **NOT** an `a` or a `b` or a `c`, | ||
| * `[^x-y]` matches exactly one character that is **NOT** in the range from `x` to `y` | ||
| * `[[:character_class:]]` matches one character that is in the named "character_class" | ||
| * the available character classes are: | ||
| * `lower` -- lowercase letters | ||
| * `upper` -- uppercase letters | ||
| * `alpha` -- letters | ||
| * `digit` -- digits | ||
| * `alnum` -- letters and digits | ||
| * `space` -- whitespace | ||
| * `blank` -- horizontal whitespace (space and tab) | ||
| * `xdigit` -- hexadecimal digits | ||
| * `word` -- characters allowed in an identifier (letters, numbers, underscore) | ||
| * `punct` -- punctuation | ||
| * `cntrl` -- control characters | ||
| * `graph` -- "visible" characters | ||
| * `print` -- visible characters plus space | ||
| * they can be combined: | ||
| * the `[[:alpha:]]` class consists of `[[:lower:][:upper:]]` | ||
| * the `[[:alnum:]]` class consists of `[[:alpha:][:digit:]]` | ||
| * the `[[:word:]]` class consists of `[[:alnum:]_]` | ||
| * underscore (octal 137) is both `[[:word:]]` and `[[:punct:]]` | ||
| * the `[[:graph:]]` class consists of `[[:alnum:][:punct:]]` | ||
| * the `[[:print:]]` class consists of `[[:graph:] ]` -- just space (octal 040) not any other whitespace. | ||
|
|
||
| ## Glob Patterns Are Not Regular Expressions | ||
|
|
||
| Glob patterns **are not** regular expressions. | ||
|
|
||
| A glob pattern must match the _entire_ filename, but a regular expression can match only part of a string. | ||
| For example, the glob `a` matches only a file named exactly `a`, while the regex `a` matches any string that contains an `a`. | ||
| To get the same result with a glob, use `*a*`. | ||
|
|
||
| * match exactly one character | ||
| * regex `.` | ||
| * glob `?` | ||
| * match zero or more characters | ||
| * regex `.*` | ||
| * glob `*` | ||
| * the glob pattern `.*` means "match a filename where the first character is a literal dot followed by zero or more of any characters". | ||
| * match one or more characters | ||
| * regex `.+` | ||
| * glob `?*` | ||
| * regex character sets and glob character sets act the same way. | ||
|
|
||
| ## Extended Patterns | ||
|
|
||
| Bash provides [extended patterns][extended-patterns] that are closer to regular expressions. | ||
|
|
||
| [extended-patterns]: https://www.gnu.org/software/bash/manual/bash.html#Pattern-Matching |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| # Advanced Word Splitting | ||
|
|
||
| (Note this material is for a future concept) | ||
|
|
||
| Any results of parameter expansion, command substitution or arithmetic expansion _that did not occur within double quotes_ are eligible for "word splitting". | ||
| The shell takes the expanded result, and splits it on any sequence of characters present in the value of `$IFS`. | ||
| By default, this is space, tab and newline. | ||
|
|
||
| Let's see it with a different value of `$IFS`: | ||
|
|
||
| ```bash | ||
| csv="first,second,third" | ||
| IFS="," | ||
| for word in $csv; do echo "$word"; done | ||
| ``` | ||
| outputs | ||
| ```none | ||
| first | ||
| second | ||
| third | ||
| ``` | ||
|
|
||
| ## Disable Word Splitting | ||
|
|
||
| A technique to disable word splitting is to set `$IFS` to an empty string | ||
|
|
||
| ```bash | ||
| sentence="The quick brown fox jumps." | ||
| IFS= # or explicitly, IFS="" | ||
| printf '%s\n' $sentence | ||
| ``` | ||
| outputs | ||
| ```none | ||
| The quick brown fox jumps. | ||
| ``` | ||
|
|
||
| However, leaving variables unquoted is not recommended unless you also disable Filename Expansion. | ||
| See [Advanced Filename Expansion](advanced-filename-expansion.md) to learn how. | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.