Filename Expansion

Filename expansion is a feature of the shell. It is one of several forms of command line expansion, by which the arguments typed on the command line by the user may not be delivered as typed to the command. Rather, they are expanded, synonym for modified, and the command is given the modification rather than the orignal.

For example, if you are in a directory that contains files named peach and pear, but no other files starting with "p," and you type

echo p*

the echo command will not be given "p*" to print. If it were, that literally is what would show up on the screen. Rather, the shell notes the set of files that begin with "p," because it gives that special interpretation to the asterisk rather than treating it literally, and delivers those filenames to echo for printing instead. The echo command receives for printing, and prints, exactly the same thing as if the user had typed

echo peach pear

I have written a demo script that shows several such examples for you to consider and learn.


The exercise for you to perform:

Obtain the script, which is called demo-filename-expansion. It resides in /home/public on the remote server, and may also be found in /home/demo on your provided virtual machine. You need to be (cd) in the directory where the script resides. You need also to change the script's permissions (chmod) to allow it to be executed:

cd
cp /home/public/demo-filename-expansion 
[ the trailing dot is essential, expressing that the copy destination is, in shorthand, the current directory ]
chmod +x demo-filename-expansion

Run it:

./demo-filename-expansion

The demo should be more or less self explanatory. Take a slow, good look at the screens and satisfy you understand what's going on.