How can I find the location of the tcsh shell script I'm executing?

Julian Mann picture Julian Mann · Apr 1, 2010 · Viewed 17.9k times · Source

Say I put an executable tcsh file in /path/to/my_script.csh

and my current directory is anywhere, for example I'm in /path

So I type to/my_script.csh

I want to have a line in my_script.csh that will return "/path/to/my_script.csh" - like ruby's

__FILE__

Answer

euccas picture euccas · Jul 25, 2014

In c shell, try like this:

set rootdir = `dirname $0`
set abs_rootdir = `cd $rootdir && pwd`
echo $abs_rootdir