function wd=cd(str)
%CD Change directory.
%   Implementation for UNIX so that ~ is supported.

%   Copyright (c) 1984-98 by The MathWorks, Inc.
%   $Revision: 1.7 $  $Date: 1997/11/21 23:31:16 $

if (nargin == 0)
  wdd = builtin('cd');
else
  if isunix & ~isempty(str)
    idx = find(str=='~');
    if (~isempty(idx))
      home = getenv('HOME');
      for k = length(idx):-1:1
        str = fullfile(str(1:idx(k)-1),home,str(idx(k)+1:end),'');
      end
    end
  end
  eval('wdd = builtin(''cd'',str);','error(lasterr)');
end

if (nargout > 0)
  wd = wdd;
end
  
