bugGNU Octave - Bugs: bug #41275, cd should display current...


bug #41275: cd should display current directory instead of changing to user home

Submitted by:  None
Submitted on:  Sun 19 Jan 2014 12:22:09 PM UTC  
Category:  Octave Function Severity:  2 - Minor
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  Wont Fix Assigned to:  None
Originator Name:  Originator Email:  -email is unavailable-
Open/Closed:  Closed Release:  dev
Operating System:  Any

Add a New Comment (Rich Markup)

You are not logged in

Please log in, so followups can be emailed to you.


( Jump to the original submission)

Mon 17 Jun 2019 04:59:34 PM UTC, comment #12: 

It's a bit embarrassing that it took so long to get back to this issue, but I've finally applied the changes from comment #10, credited to Michael:


Leaving the status as "Won't fix" because we are still not 100% compatible, as discussed here previously.

See also bug #56471 where this issue came up in a function that was using cd to get the current directory.

John W. Eaton <jwe>
Project Administrator
Fri 29 Sep 2017 05:22:57 PM UTC, comment #11: 

Will the patch provided be applied? At least in 4.2.1 it doesn't work the way described (a=cd; still changes the directory). It would definitely be useful for using matlab libraries.

Marshall <marsian>
Tue 11 Feb 2014 06:02:25 PM UTC, comment #10: 

Two patches provided: one for dirfns.cc and one for system.tst

(file #30516, file #30517)

Michael C. Grant <mcgrant>
Tue 11 Feb 2014 05:52:58 PM UTC, comment #9: 

I've patched dirfns.cc. I'm testing it now, and I'll upload a change set here when I am finished.

Michael C. Grant <mcgrant>
Tue 11 Feb 2014 05:43:23 PM UTC, comment #8: 

It must be something like that, because...

>> pwd
ans = /Users/mcgrant/Projects/CVX/examples/antenna_array_design
>> test = cd;
>> pwd
ans = /Users/mcgrant
>> version
ans = 3.9.0+

Michael C. Grant <mcgrant>
Tue 11 Feb 2014 05:40:41 PM UTC, comment #7: 

I thought that's what we already did.  I'm pretty sure I proposed that behavior at some point.  Maybe I failed to follow through on making the change.  Or maybe I just said that I would accept such a change but no one ever provided a patch or it was never applied.

John W. Eaton <jwe>
Project Administrator
Tue 11 Feb 2014 05:08:09 PM UTC, comment #6: 

Let me add, however, that you could eliminate probably >95% of the incompatibilities while still preserving the UNIX-like behavior if you differentiate between nargout==0 and nargout==1. That is:

odir = cd;

would act just like pwd (nargout==1), while


would behave as you expect it to; that is, changing the directory to the home directory.

Michael C. Grant <mcgrant>
Tue 11 Feb 2014 04:59:56 PM UTC, comment #5: 

I just wanted to add for the record that this incompatibility is breaking CVX. Now as luck would have it, I am the author of CVX, so I can correct this. But I'm still grumbling.

Michael C. Grant <mcgrant>
Tue 21 Jan 2014 10:26:32 PM UTC, comment #4: 

Octave prefers the UNIX style functionality of 'cd' so this won't be changed.  But, there are plenty of workarounds either through re-coding or using a modified cd.m.

Rik <rik5>
Project Administrator
Sun 19 Jan 2014 06:36:31 PM UTC, comment #3: 

The following cd.m function file should provide the equivalent Matlab-compatible behavior without patching anything.


Mike Miller <mtmiller>
Project Administrator
Sun 19 Jan 2014 06:23:22 PM UTC, comment #2: 

Ah, I see.
The reason I posted this bug report was that I wanted to use the Stanford Wavelet toolbox with Octave. Unfortunately, they use the cd command. Rather than starting to patch all the sources out there, I would have liked to change Octave behavior.

Maybe I can write cd.m to show the built-in function and provide Matlab-compatibility.

Sun 19 Jan 2014 05:13:20 PM UTC, comment #1: 

This is an intentional difference with Matlab, see "help cd", it is quite clear about the difference in compatibility for this command.

See also this recent maintainer discussion about the issue: http://octave.1599824.n4.nabble.com/Matlab-incompatibility-cd-and-which-td4658188.html

The consensus for now seems to be to keep the current incompatible behavior. If you want to be compatible between Matlab and Octave try to use the pwd function.

If cd is ever made to be compatible, there will not be a configuration option, it will just adopt the inconvenient Matlab behavior.

Marking as postponed since this will probably require some discussion and will not happen in a 3.8.x release. Feel free to comment further with compelling reasons to adopt this compatibility rather than preferring the POSIX standard behavior.

Mike Miller <mtmiller>
Project Administrator
Sun 19 Jan 2014 12:22:09 PM UTC, original submission:  

In Matlab the command


will return the current directory (same as pwd) and stay in the same directory.

In Octave, issuing "cd" will not print the current directory, but instead change the working directory to the user profile folder. (Win7, Octave 3.8)

Can this be changed?
I know, that this is the default way cd works in Linux, but maybe there could be an option "use Matlab-style cd command".

I also know, that

curDir = cd

will save the current directory, but it then still changes to user profile folder. Anyway, the default behavior of cd is not Matlab compatible.



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

Attach Files:

Attached Files
file #30516:  cd.diff added by mcgrant (1KiB - application/octet-stream)
file #30517:  cdtest.diff added by mcgrant (567B - application/octet-stream)


Depends on the following items: None found

   bug dependencies.


Carbon-Copy List
  • -email is unavailable- added by marsian (Posted a comment)
  • -email is unavailable- added by jwe (Posted a comment)
  • -email is unavailable- added by mcgrant (Posted a comment)
  • -email is unavailable- added by rik5 (Posted a comment)

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.




    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2019-06-17 mtmiller Carbon-CopyRemoved 80942 => -
    2019-06-17 jwe Dependencies- => bugs #56471 is dependent
    2014-02-11 mcgrant Attached File- => Added cd.diff, #30516
        Attached File- => Added cdtest.diff, #30517
    2014-01-21 rik5 StatusPostponed => Wont Fix
        Open/ClosedOpen => Closed
        Summarycd should display current directory instead of changin to user home => cd should display current directory instead of changing to user home
    2014-01-19 mtmiller Severity3 - Normal => 2 - Minor
        StatusNone => Postponed
        Release3.8.0 => dev
        Operating SystemMicrosoft Windows => Any

    Back to the top

    Powered by Savane 3.5