How do I get `__FILE__` when sourcing a csh script
If you access $_
on the first line of the file, it will contain the name of the file if it's sourced. If it's run directly then $0
will contain the name.
#!/bin/tcsh
set called=($_)
if ($called[2] != "") echo "Sourced: $called[2]"
if ($0 != "tcsh") echo "Called: $0"
This is hard to read, but is actually works:
If your script is named test.csh
/usr/sbin/lsof +p $$ | \grep -oE /.\*test.csh