Exercise
Shell Expansions Exercise
Overview
Bash inspects your command line before the command runs,
and it replaces pattern characters such as
*, ?, and
[...] with matching file names.
In this hands-on exercise you will navigate to
/etc/ssh on servera, match
real configuration files and host keys using each glob
pattern, and observe pathname expansion directly with
echo.
- Target host
servera
-
Match file names with an asterisk (*)
Connect to
servera, change to the/etc/sshdirectory, and list all files. Then list all public host key files ending in.pub, followed by all configuration files ending withconfig.ssh student@servera cd /etc/ssh ls ls *.pub ls *config -
Match single characters with a question mark (?)
The question mark (
?) matches exactly one character. Runlsto review the directory, then use?to match files with specific character lengths.ls ls ssh?_config ls ssh_host_???_key.pub -
Match character sets with brackets ([...])
Brackets (
[...]) match any single character from the specified set or range. Compare matching specific algorithm prefixes with matching numeric digits.ls ssh_host_[e]*.pub ls ssh_host_[r]*.pub ls ssh_host_[re]*.pub ls *[0-9]* -
Observe pathname expansion directly with echo
Run
echowith unquoted patterns to see how Bash expands globs into arguments before the command runs.echo * echo *.pub