Shell expansions
While working with shell, we perform a lot of similar and repetitive tasks. For example, in the current directory, there are 100 files but we are interested only in shell script whose file extension is .sh
. We can execute following command to view only shell script files in current directory:
$ ls *.sh
This will show all the files ending with .sh
. An interesting take away from here is the *
wildcard. It means a match list of files whose name can be anything and that ends with .sh
.
Shell expands all wildcard patterns. A list of the latest wildcard patterns are as follows:
- ~ (Tilde)
- * (Asterisk)
- ? (Question mark)
- [ ] (Square brackets)
- { } (Curly brackets)
To explain shell expansion for different wildcards, we will create a test folder ...
Get Linux Shell Scripting Essentials now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.