next up previous 405
Next: Process a Series of Files
Up: Dealing with Files
Previous: Dealing with Files


Extracting parts of filenames

Occasionally you'll want to work with parts of a filename, such as the path or the file type. The C-shell provides filename modifiers that select the various portions. A couple are shown in the example below.

     set type = $1:e
     set name = $1:r
     if ( $type == "bdf" ) then
        echo "Use BDF2NDF on a VAX to convert the Interim file $1"
     else if ( $type != "dst" ) then
        hdstrace $name
     else
        hdstrace @'"$1"'
     endif

Suppose the first argument of a script, $1, is a filename called galaxy.bdf. The value of variable type is bdf and name equates to galaxy because of the presence of the filename modifiers :e and :r. The rest of the script uses the file type to control the processing, in this case to provide a listing of the contents of a data file using the HDSTRACE utility.

The complete list of modifiers, their meanings, and examples is presented in the table below.


Modifier Value returned Value for filename
    /star/bin/kappa/comwest.sdf
     
:e Portion of the filename following a full stop; if the filename does not contain a full stop, it returns a null string sdf
:r Portion of the filename preceding a full stop; if there is no full stop present, it returns the complete filename comwest
:h The path of the filename (mnemonic: h for head) /star/bin/kappa
:t The tail of the file specification, excluding the path comwest.sdf
     




next up previous 405
Next: Process a Series of Files
Up: Dealing with Files
Previous: Dealing with Files

C-shell Cookbook
Starlink Cookbook 4
Malcolm J. Currie
2006 November 26
E-mail:ussc@star.rl.ac.uk

Copyright © 2008 Science and Technology Facilities Council