Difference between revisions of "bash/globbing"
< bash
Jump to navigation
Jump to search
(Created page with "The following notes may apply to other shell environments besides bash, but have only been tested with bash. Commands invoked via bash always, by default, have each o...") |
(problem, workarounds, TC post) |
||
Line 2: | Line 2: | ||
Commands invoked via bash always, by default, have each of their arguments parsed via the [[glob]] system facility before being passed to the command. | Commands invoked via bash always, by default, have each of their arguments parsed via the [[glob]] system facility before being passed to the command. | ||
− | + | ==Problem== | |
+ | This actively interferes with the ability of programs such as [[grep/file masks|grep]] to behave intuitively when given a file-mask spec as input for processing, because: | ||
+ | * any mask entered will apply only to the current folder. | ||
+ | * folders are only included if their names ''also'' match the mask | ||
+ | ** ...thus not being useful as far as being the next layer of folders to search; the program will have to get its own directory listing for that. | ||
+ | ===Workarounds=== | ||
Globbing can be turned off on a per-session basis: | Globbing can be turned off on a per-session basis: | ||
* <code>set -o noglob</code> | * <code>set -o noglob</code> | ||
Line 11: | Line 16: | ||
* <code>help set</code> | * <code>help set</code> | ||
*: returns more information about bash's <code>set</code> command (the "set" manpage is for something else) | *: returns more information about bash's <code>set</code> command (the "set" manpage is for something else) | ||
+ | |||
+ | The user can bypass globbing (and other special-character processing) by enclosing the file-mask in quotes (single or double). bash will strip off the quotes but not parse the contents. | ||
==Links== | ==Links== | ||
* {{l/manpage|glob}} | * {{l/manpage|glob}} | ||
* {{wikipedia|glob (programming)}} | * {{wikipedia|glob (programming)}} | ||
* [https://www.php.net/manual/en/function.glob.php PHP: glob] | * [https://www.php.net/manual/en/function.glob.php PHP: glob] | ||
+ | * '''2020-02-04''' [https://toot.cat/@woozle/103603799224715530 Linux hot take: bash bashing] |
Revision as of 18:44, 5 February 2020
The following notes may apply to other shell environments besides bash, but have only been tested with bash.
Commands invoked via bash always, by default, have each of their arguments parsed via the glob system facility before being passed to the command.
Problem
This actively interferes with the ability of programs such as grep to behave intuitively when given a file-mask spec as input for processing, because:
- any mask entered will apply only to the current folder.
- folders are only included if their names also match the mask
- ...thus not being useful as far as being the next layer of folders to search; the program will have to get its own directory listing for that.
Workarounds
Globbing can be turned off on a per-session basis:
set -o noglob
- turns off globbing
- put it in
~/.bashrc
to make it the default
set +o noglob
- turns globbing back on
help set
- returns more information about bash's
set
command (the "set" manpage is for something else)
- returns more information about bash's
The user can bypass globbing (and other special-character processing) by enclosing the file-mask in quotes (single or double). bash will strip off the quotes but not parse the contents.
Links
- glob
- Wikipedia
- PHP: glob
- 2020-02-04 Linux hot take: bash bashing