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
  1. Match file names with an asterisk (*)

    Connect to servera, change to the /etc/ssh directory, and list all files. Then list all public host key files ending in .pub, followed by all configuration files ending with config.

    ssh student@servera
    cd /etc/ssh
    ls
    ls *.pub
    ls *config
  2. Match single characters with a question mark (?)

    The question mark (?) matches exactly one character. Run ls to review the directory, then use ? to match files with specific character lengths.

    ls
    ls ssh?_config
    ls ssh_host_???_key.pub
  3. 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]*
  4. Observe pathname expansion directly with echo

    Run echo with unquoted patterns to see how Bash expands globs into arguments before the command runs.

    echo *
    echo *.pub