Jay Taylor's notes

back to listing index

Bash wildcards: the square brackets [ ] and the curly brackets { } | LinuxG.net

[web search]
Original source (linuxg.net)
Tags: bash shell linux tips shell-scripting quick-reference linuxg.net
Clipped on: 2021-09-21

Bash wildcards: the square brackets [ ] and the curly brackets { }

In the previous wildcard post, I taught you how to use the asterisk * and the question mark ? wildcards. This article is about other, not so popular wildcards: the square brackets [ ] and the curly brackets {}.

Note: These article is about the bash wildcards. The wildcards depend on the shell, not on the Operating System, so not all the bash wildcards work for other shells.

The bash square brackets [ ] wildcards:

The shell matches one character from the letters or digits inside the curly brackets: [123456], [abcde] or [1-6] [a-e] . If there is the ! character present inside the square brackets [ ], the shell will choose one character/digit not listed in the brackets: [!a-h], [!123].

$ ls
file1 file2 file3 file4 file5 file6
$ ls file[1-3]
file1 file2 file3
$ ls file[!146]
file2 file3 file5

The bash curly brackets { } wildcard:

The shell matches one word inside the curly brackets: {linux,unix} .

$ ls
file_BSD file_linux file_unix
$ ls file_{unix,linux}
file_linux file_unix

Leave a Reply

Your email address will not be published. Required fields are marked *

Comment

Name *

E-mail *

Website

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!