Search code examples
pathtcsh

how can I strip the filename from a path in tcsh?


Given this variable in tcsh:

set i = ~/foo/bar.c

how can I get just the directory part of $i?

~/foo

Solution

  • If your system provides a 'dirname' command you could:

    set i = `dirname ~/foo/bar.c`
    echo $i
    

    Note the missing $ in front of the variable name. This solution is shell agnostic though.