Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Issues with "source"

Status
Not open for further replies.

skywalkr2

Programmer
Mar 3, 2006
17
US
Hello all,

I am trying to get some of our old code to work, and have been having some troubles this morning. I was wondering if someone could help me.

My environment is HPUX running under ksh. I am having problems with the following statements:

set data [exec which macmenu_source_files]
source $data

If I do this, then I get an error of couldn't read file: no such file or directory. However, if I modify the code to this, then it works (the file macmenu_source_files is executable):

source macmenu_source_files

I need to be able to get the first method to work. Does anyone have any ideas why the first command would work and the second would not?
 
Are you sure this ever worked? I have never known an exec statement to return anything useful.

What does the which command do? From the succeeding statement, it would appear that it returns the value macmenu_source_files. Is that what it's supposed to do?

_________________
Bob Rashkin
 
Yes - this is code that we used back in 1998 to produce menus for running several other programs. The unix command which just returns the path to the executable you want to execute. So "which macmenu_source_files" returns: "/conv1/bin/macmenu_source_files". I assign the returned value to $data and then I just do source $data.

That's when I get the error. It has a problem when the patch is passed into the source command.
 
If you were to do the following,
Code:
set data [exec which macmenu_source_files]
puts $data
what would you see?

_________________
Bob Rashkin
 
This is the exact two lines right before the source command. These process fine. The problem occurs on the 3rd line: source $data.
 
Sorry - you lost me there. Is there a flag we need to use to determine the return code for each line being executed? I have never needed to use it. **Actually it's been like 5 years since I modified TCL code**
 
The point here is to determine what is the value of the variable, data after the statement:
Code:
set data [exec which macmenu_source_files]

_________________
Bob Rashkin
 
Sorry - brain dead - The puts displays:

./macmenu_source_files

This is the location of the file we are trying to source in.
 
So, let's see if I've got this straight:
1. you have successfully executed a statement that sets [red]data[/red] equal to [red]./macmenu_source_files[/red]
2. if you execute the statement, source ./macmenu_source_files, everything works fine
3. if you execture the statement, source $data, it doesn't work

Is that correct? You can see why it might seem unbelievable to a casual observer, right?

Just for grins, what happens if you execute:
Code:
set data "macmenu_source_files"
source $data

_________________
Bob Rashkin
 
No - it won't work if I have ./macmenu_source_files in data. It fails with file not found.

If however I have "macmenu_source_files" by itself it DOES work.
 
OK. Now we have something! I'm not sure what, though. Is the correct Tcl script in your current directory (which is what I take ./ to be)?

Will it be sufficient to strip off the "./" from the start of $data? If so, the following will work:
Code:
set data [exec which macmenu_source_files]
set data [string map {./ ""} $data]
source $data

_________________
Bob Rashkin
 
That will probably work. ./ is the directory because we cd to the location of the files prior to execution. I will try this. Crossing my fingers.
 
I will have to look up the map command. I am getting this error: bad option "map": should be compare, first, index, last, length, match, range, tolower, toupper, trim, trimleft, trimright, wordend, or wordstart
 
Instead I have been trying to use string trimleft and cannot seem to get it to trim off the ./ special characters
 
When in doubt, use regular expressions:
regsub "./" $data "" data

_________________
Bob Rashkin
 
The regular expression worked. I must have a problem with our interpreter. After the regular expression, the variable data was set to macmenu_source files. However, it still did not work. So, I am at a loss...

source $data (where data = "macmenu_source_files")
doesn't work, but
source macmenu_source_files
does work...
 
Now, that's just crazy talk.
Let's go back to the beginning:
Code:
set data macmenu_source_files
source $data

Does that work?


_________________
Bob Rashkin
 
Yes - that DOES work. But for some reason if you use the regular expression to set it to the exact same text... it doesn't work? Very odd...
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top