Bash - pathname expansion (Filename expansion)

Bash Liste Des Attaques Ovh

About

pathname or filename expansion 1) is an expansion (code replacement at runtime) that replaces globbing wildcard by pathname.

The path name in this context is the last part in a path, it is therefore equivalent to the file name

Example

Asterisk

The asterisk character matches every filename in a given directory.

Example: The examples have the following files in their current directory

foo.txt
bar.txt

Example 1

The following echo command

echo * 

will expand to all files in the current directory and will be equivalent at runtime to the following command

echo foo.txt bar.txt

and will effectively list all files in the current directory

foo.txt bar.txt



Example 2 The following echo command

echo b* 

will expand to all files that starts with a b in the current directory and will be equivalent at runtime to the following command

echo bar.txt

listing only the bar file

bar.txt

Question Mark

  • ? matches a single character
echo t?.sh # will list the file that start with t and have two characters

If there is no match, the expression is just echoed

Double Asteriks

The globstar parameters should be set to enable Glob - Globbing (Wildcard expression)

shopt -s globstar
ls **/
shopt -u globstar
ls **/

If followed by a /, two adjacent *s will match only directories and subdirectories.

Braces

braces globbing is supported on the last bash version

ls -l {b*,c*,*est*}

Not to confound with brace expansion that generates string.

Documentation / Reference

More on globbing pathnames or

man 7 glob | col -b > glob.txt





Discover More
Bash Liste Des Attaques Ovh
Bash - Brace Expansion {} (Data Generation)

Brace expansion is a mechanism by which arbitrary strings may be generated. This mechanism is similar to pathname expansion, but the filenames generated need not exist. Patterns to be brace expanded...
Bash Liste Des Attaques Ovh
Bash - (Environment) Variable

A variable is a parameters referenced by a name. parameter A variable has: a value and zero or more attributes (such as integer, ...). Attributes are assigned using the declare builtin command....
Bash Liste Des Attaques Ovh
Bash - Case

The case control statement execute commands based on regular expression pattern matching. Initscript example: Selectively execute COMMANDS based upon WORD matching glob PATTERN. The | is used to...
Bash Liste Des Attaques Ovh
Bash - Conditional Expression

A predicate or boolean expression is known in Bash as a Conditional Expression. It is a command that returns an exit status of 0 or 1. The conditional expression is part of the compound expression. ...
Bash Liste Des Attaques Ovh
Bash - Expansion

This article is expansion in Bash. An expansion is the replacement of a special token in your code by the result of the expansion during code execution. It's performed on the command line after it has...
Bash Liste Des Attaques Ovh
Bash - Here Documents

in Bash. Here document in Bash is implemented through redirection. A redirection instructs the shell to read input from the current source until a line containing only word (with no trailing blanks)...
Bash Liste Des Attaques Ovh
Bash - Parameter Expansion ${

Parameter expansion are patterns applied to the parameters that have different results. Same as ?? See also: The value of parameter is substituted where: the braces are optional. They served...
Bash Liste Des Attaques Ovh
Bash - Path

This article is the path management in bash. ie /dir/childDir/fileName. See also:
Regexp
Glob - Globbing (Wildcard expression)

Glob isNOT a regular language but is wildly used to define a set of filenames with wildcard characters. For instance, Bash provide globbing on filenames. The syntax is different by implementation and...
Bash Liste Des Attaques Ovh
How to use Regular expression (regex) in Bash?

This article shous you how to use regular expression in Bash This example shows you how you can capture a Group to extract text. Example where we will extract a part of a file name When the...



Share this page:
Follow us:
Task Runner