Generating Dynamic Pathnames
Shell·2 min read·Jan 1, 2025
The shell expansion refers to the process by which the shell interprets certain special characters or character sequences and expands them into treatable command parameters before executing a command.
In Bash, there are essentially three expansions for dynamically generating pathnames based on patterns:
-
The tilde expansion
-
The wildcard expansion
-
The brace expansion
The tilde expansion
In Bash, the tilde character ~ is a shortcut for the path to the home directory.
It is used to write relative pathnames, starting from the home directory, regardless of the current working directory.
Example
For example, assuming the current user account is johndoe, the following command will change the current working directory to /home/johndoe/Documents on Linux and /Users/johndoe/Documents on macOS:
$ cd ~/DocumentsUnlock the CLI & Scripting with Bash module
Learn how to gain advanced control over the OS and automate complex routine tasks prone to manual errors with the CLI and Bash scripting.
You get immediate access to:
- 34 focused lessons across the CLI and Bash
- 4 real-world projects with commented solutions
- Ongoing updates to this bundle
- Lifetime access to this bundle