Strange behavior of "which" command in Matlab for Linux

I am working with the Unix version of Matlab R2015a under Fedora 22. I just found that if a execute the command

which filename

when I am located in a folder different than the folder where filename is located, I would get the full path of filename but with an extra folder "/.". For example, suppose that the full path of filename that I get when I run the command in the folder where filename is located is

/home/user/Documents/MATLAB/Apps/project/filename.m

Then, the path that I get when I am located in a different folder would be

/home/user/Documents/MATLAB/Apps/project/./filename.m

I tested the command over R2012 in Windows and the behavior is the expected, that is, the full path name is the same no matter where you are located.

My matlabroot: /usr/local/MATLAB/R2015a

My userpath: /home/user/Documents/MATLAB/

In my path I have a lot of other folders, including all subfolders of userpath.

Has somebody else experienced this behavior? Any explanation or solution?

Upvotes: 1

Views: 62

Answers (1)

Ludwig Schulze
Ludwig Schulze

Reputation: 2315

It may be unexpected but it is not an error:

(1) The path is still correct. "." (dot) is a reference to the directory that it contains this entry. This is required by POSIX http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap04.html (see section 4.12) .

(2) Mathworks documentation specifies that "which" returns the "full path". It does not give a definition for "full path". In my book they are free to use a meaning of "full path" that allows "." directory self-references in the path.

Edit: As for "solution" and "explanation":

Solution: You can get rid of the extra dot directory with

strrep(which('filename'),'/./','/')

No Explanation:

Mathworks has not made the source code of their "which" function available. Therefore, only they can explain the behaviour. Contact customer support. In addition to the information you have provided so far, they might also need the output of the matlab "path" commando in your installation environment to be able to explain it.

Upvotes: 3

Related Questions