People new to using csh history expansion are often confused by an apparent ambiguity regarding the order in which wildcard expansion and history expansion occur. For instance, in the sequence of commands
   % ls -l x*
   % echo !$
does the echo print the name of the last file listed by the ls command, or does the !$ expand to x*, causing the shell to see "echo x*"?

It turns out that the latter is the case, for the simple reason that it is far more often the Right Thing.

However, it should be noted that (by default) the shell considers the previous line after history expansion, so

   % cat !$
following the preceding 2 lines would cat all files beginning in x, not the file named "!$". This, too, is usually a Right Thing.

Log in or register to write something here or to contact authors.