The double asterisk (**)

The double asterisk is being used in two different contexts:

  • It is used as a exponentiation operator in an arithmetic context
  • It is used as an extended file match globbing operator from Bash 4, meaning it matches filenames and directories recursively

So, we have this:

zarrelli:~$ for i in * ; do echo "$i" ; done
file
test2

This is different from the following:

zarrelli:~$ for i in ** ; do echo "$i" ; done
file
test2
test2/file2

The double star matched all files and directories globally. If the double star does not work for you, enable the globstar shell options with zarrelli:~$ shopt -s globstar ; for i in ** ; do echo "$i" ; done. The globstar value changes the way the shell interprets the double star, which, in a file name expansion, matches all files and any subdirectories. If the pattern is followed by a /, only the directories and subdirectories will be matched:

zarrelli:~$ for i in **/ ; do echo "$i" ; done
test2/
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.23.101.60