I am sourcing a file under tcsh. This file could be anywhere on the filesystem. How can I retrieve the path of my sourced file ?
$0 won't work : I don't execute the file, I source it.
Many thanks !
|
I am sourcing a file under tcsh. This file could be anywhere on the filesystem. How can I retrieve the path of my sourced file ? $0 won't work : I don't execute the file, I source it. Many thanks ! | |||
|
feedback
|
|
As far as I know sourcing means that you run it as if you were typing the commands one by one in the command line. Then, of course, you can't access its name, because he's not being executed as a script in the first place. But you might be lucky: try to look in the command log. In | |||
|
feedback
|
|
While this is possible in other shells, I don't see a way to do it in | |||||||
feedback
|
|
A little bit of grepping gives me what I want. There is one thing I know for sure : the basename of the file (not the whole path). In my case, source_me.tcsh. So we can query lsof for the current shell PID and grep the absolute path. $$ gives you the PID.
| |||
|
feedback
|