From the course: Bash Patterns and Regular Expressions

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Shell globbing options

Shell globbing options - Bash Tutorial

From the course: Bash Patterns and Regular Expressions

Start my 1-month free trial

Shell globbing options

- Depending on your version of Bash, there may be other shell options that can make globbing more powerful. Namely, nullglob, failglob, dotglob, globstar, nocasematch, nocaseglob, and extglob. To set a shell variable, use the shopt, space, dash, S syntax. To unset it, use shopt space, dash, U, and to print out the current values, type in shopt, space, dash P. The first option we'll look at is nullglob. The nullglob option expands non-matching globs to a null instead of to themselves. In this example, if we have files that end with dot, bin, then this loop will loop through them in free generation, the value of dollar sign, I will be the file name. For instance, file one, dot, bin, file two, dot, bin and so on. However, if there are no files ending in dot, bin, then the value of dollar sign, I will be set to the literal string of asterisk, dot, bin. An echo will print asterisk, dot, bin on the screen and the value of the found variable will be set to one, which is incorrect. If we set…

Contents