bugGNU Octave - Bugs: bug #62961, script search path seems not to...

 
 

bug #62961: script search path seems not to update to current directory in a script

Submitter:  None
Submitted:  Fri 26 Aug 2022 08:10:07 PM UTC
   
 
Category:  Other Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Incorrect Result
Status:  Confirmed Assigned to:  None
Originator Name:  Alex Barnett Originator Email:  -email is unavailable-
Open/Closed:  * Open Release:  * dev
Operating System:  * Any Fixed Release:  None
Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Sat 27 Aug 2022 09:17:33 PM UTC, comment #1: 

Thanks for reporting.

To recreate your problem, I've created the following script from your example and called it bug62961_cd_oath.m:

cd a; test
cd ../b; test
cd ..


then created two subdirs 'a' and 'b' and I've put a script file 'test.m' with the following content in 'a':

printf ((from a) "%s\n", pwd);


similiarly for subdir 'b':

printf ((from b) "%s\n", pwd);


and then ran 'bug62961_cd_path.m' from the directory containing 'a' and 'b':

>> bug62961_cd_path
(from a) C:\Users\philip\MyDocs\octave\a
(from a) C:\Users\philip\MyDocs\octave\b
>>


Matlab r2020b gives (after changing 'printf' into 'fprintf' and " -> '):

>> bug62961_cd_path
(from a) C:\Users\philip\MyDocs\octave\a
(from b) C:\Users\philip\MyDocs\octave\b
>>


so there it works as expected. At least, Octave doesn't behave Matlab-compatible here.

Status -> 'Confirmed'
OS -> Any   (I tried on Windows 10)
Release ->  dev  (I'm using Octave-8.0.0)

Philip Nienhuis <philipnienhuis>
Group Member
Fri 26 Aug 2022 08:10:07 PM UTC, original submission:  

It seems the script search path (and I've found the mex search path too) fails to update upon a cd when done in a script (not using the command line).

The below example should output:
ans = hello from a
ans = hello from b
It does not on my ubuntu octave 6.4.0, on ubuntu/popos 22.04. It incorrectly produces:
ans = hello from a
ans = hello from a

Here is minimally complete example from bash:

mkdir a
cat <<EOF > a/test.m
"hello from a"
EOF
mkdir b
cat <<EOF > b/test.m
"hello from b"
EOF
cat <<EOF > bug.m
cd a; test
cd ../b; test
EOF
octave bug.m


Output:
ans = hello from a
ans = hello from a

However, opening octave and using command line (not script!)
gives expected output:

octave:2> cd a; test
ans = hello from a
octave:3> cd ../b; test
ans = hello from b


I didn't have time to look into the cause, but I can verify that:
1) which('test') fails to change after 2nd cd, verifying the bug,
2) pause(1) makes no difference, the bug is still there,
3) addpath(.) inserted after the 2nd cd is a workaround.

Thanks!  Alex



Anonymous

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by None (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    Follow 3 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2022-08-27 philipnienhuis StatusNone Confirmed
        Release6.4.0 dev
        Operating SystemGNU/Linux Any

    Back to the top

    Powered by Savane 3.13-f8d8.
    Corresponding source code