C Shell Scripting/Modifiers

Variable Modifiers
In C shell, the path value obtained from a variable can be modified before it is used into a command or expression. Variable modifiers are given after a colon at the end of a variable. The meaning of the modifiers are as follows:

returns the directory of a path (aka "head") returns the filename of a path (aka "tail") returns the directory and filename without the last extension (aka "root") returns the extension of the path (aka "end")

For example, using this script:

set file = /usr/joe/backup.tar.gz echo $file:h echo $file:t echo $file:r echo $file:e echo $file:t:r:r echo $file:h:h
 * 1) !/bin/csh -f

will produce this:

/usr/joe backup.tar.gz /usr/joe/backup.tar gz backup /usr

Lessons

 * 1) Variable modifiers are convenient to manipulate paths within the script.
 * 2) tcsh allows chaining modifiers together but some implementations only support one modifier at a time.
 * 3) Concatenating a variable with a colon character requires code such as  or   to avoid a "Bad : modifier" error.