When you are using some commands, such as: LS, git, just met some requirements is to easily traverse all the directories and files, and then after the search, finally found a "magic" wildcard "* *" (two asterisks), after setting the bash globstar option, * * You can match any current directory (including subdirectories) and the files in it. So, to understand the Globstar this option, when not set Globstar, * * Wildcard function and * is the same, and set the Globstar, * * Matching range is different (a wider). Note: Globstar is an option that was introduced in Bash 4.0, and previous versions are not supported and use "bash–version" to produce the version of Bash currently in use.
About the word glob, I also feel curious, Chinese is not easy to explain, is roughly the "spread of the wildcard" meaning, such as the following English bar:
In Shell-speak, globbing are what the shell does when your use a wildcard in a command (e.g. * or?). Globbing is matching the wildcard pattern and returning the file and directory names that match and then replacing the Wil Dcard the command with the matched items.
In Bash's man page, the description of Globstar mentioned only two times, saying the same thing, as follows:
The code is as follows |
Copy Code |
Pathname expansion ...... * matches any string, including the null string. When the Globstar shell option was enabled, and * is Used in a pathname expansion context, two adjacent *s used as a I-match all files and zero or more directories and subdirectories. If followed by A/, two adjacent *s'll match only Directories and subdirectories. ...... Globstar If set, the pattern * * used in a pathname expansion context would match a files and zero or more directories and subdirectories. The If is followed by A/, only directories and subdirectories match. |
Write a test and learn the Globstar shell script as follows:
The code is as follows |
Copy Code |
#!/bin/bash <pre lang= "Bash" > Function Show () { For i in * * Todo Echo $i Done }
cd/root/jay/ echo "------------------------" echo "Disable Globstar option:" # Globstar is disabled by default Shopt-u Globstar Show echo "------------------------" echo "Enable Globstar option:" Shopt-s Globstar Show Executing the shell script of the test Globstar above, looking at its output, it is easy to understand Globstar, as follows: [Root@smilejay jay]#./test_globstar.sh ------------------------ Disable Globstar option: Dir1 Dir2 File1 File2 Index.html test_shopt.sh ------------------------ Enable Globstar option: Dir1 Dir1/file3 Dir2 Dir2/file4 File1 File2 Index.html test_shopt.sh |