University Systems --> TerpConnect --> All TerpConnect Pages --> Examples of the Modifiers in Unix -->

Examples of the Modifiers in Unix

h
Removes the last component of a path name
r
removes the last component of the suffix of a file name (the .xxx part of a file name)
e
removes all but the suffix of a file name (including the .)
s/x/y/
substitutes the first occurrence of string x with string y in a word (note: while it is possible to do this with multiple words using the g& modifier, it is not possible to do the change globally to a word). On the command line, a string from the last command can be changed by using ^x^y
t
Removes all of the last path name from a word, everything including the last / in a word is removed
&
repeats the previous substitution on the current word

Due to bugs in csh, the use of modifiers with variables is flaky. Only the first word of the variable is visible to the modifier, syntax errors will occur on perfectly valid uses of modifiers, and combinations of modifiers (i.e. modifier:modifier:modifer) are not allowed. So, other than the modifiers that remove parts of the path/file name, use of modifiers with variables is not very useful.

That said, we will use a history event as our example:

ls /homes2/firstaid/progasst/firstaid/UGLIWSL.ps
  • "echo !ls:$:h" strips off the last component of /homes2/firstaid/progasst/firstaid/UGLIWSL.ps which is the file name, so it is reduced to

    echo /homes2/firstaid/progasst/firstaid

  • "echo !ls:$:r" strips off the trailing .ps part, reducing it to

    echo /homes2/firstaid/progasst/firstaid/UGLIWSL

  • "echo !ls:$:e" does the exact opposite of the above, leaving just the .ps part:

    echo ps

  • "echo !ls:$:s/UGLI/PGII" changes /homes2/firstaid/progasst/firstaid/UGLIWSL.ps to /homes2/firstaid/progasst/firstaid/PGIIWSL.ps

    If we wanted to perform another substitution of UGLI to PGII later on using a modifier in another command, we would use & in place of s/UGLI/PGII.

How are we doing? Comments on this page?
Office of Information Technology
Office of Information Technology Help Desk Web Site University of Maryland Web Site Office of Information Technology Web Site