Re: Tcl source command directory



brianlum@xxxxxxxxx wrote:
I am trying to use the source command, but source only looks in the
directory where I am calling the script from, i.e. the current working
directory.

For example, if my script is in /usr/local/bin/ and if i call the
script with an absolute path from my home directory /home/user/, source
only looks for files in /home/user/.

How can I make source look in the same directory where the script is
located? I need to be able to use this as I put the script on multiple
machines and it is not always in the same directory.

Thank you for your help!


I presume what you are asking for is how to source something relative to the location of a script vs the current working directory.

So, if you wanted to source in the script foobar.tcl that is in the lib directory one up and over from the location of the current script (i.e. in your example it would be /usr/local/lib/foobar.tcl) then do:

set baseDir [file dirname [info script] ]
source [file join $baseDir .. lib foobar.tcl]

--
+--------------------------------+---------------------------------------+
| Gerald W. Lester |
|"The man who fights for his ideals is the man who is alive." - Cervantes|
+------------------------------------------------------------------------+
.



Relevant Pages

  • Re: Create New User and Home Directory
    ... Compile error: Invalid Inside Procedure ... The script can be modified to create home directories for existing users. ... program that modifies profilePath for users linked here: ... The script assigns values for home directory, ...
    (microsoft.public.windows.server.active_directory)
  • Re: Create New User and Home Directory
    ... when I try to create a user who has a home directory listed on ... The user gets created, but the folder doesn't. ... rights, and just used the default ones for everyone else. ... The script can be run from any computer joined to the domain, ...
    (microsoft.public.windows.server.active_directory)
  • Re: Create New User and Home Directory
    ... when I try to create a user who has a home directory listed on ... The user gets created, but the folder doesn't. ... rights, and just used the default ones for everyone else. ... The script can be run from any computer joined to the domain, ...
    (microsoft.public.windows.server.active_directory)
  • Re: Create New User and Home Directory
    ... when I try to create a user who has a home directory listed on the ... rights, and just used the default ones for everyone else. ... The script can be modified to create home directories for existing users. ... similar program that modifies profilePath for users linked here: ...
    (microsoft.public.windows.server.active_directory)
  • Re: Error in script "invalid interpreter" (longish)
    ... Mike McCarty wrote: ... > burned the files onto CDROM. ... The script is on the CDROM. ... You could copy the script to your home directory and change ...
    (Fedora)