[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: inconsistent output for cd

From: Tony Balinski
Subject: Re: inconsistent output for cd
Date: Tue, 03 Apr 2007 13:49:48 -0400
User-agent: Internet Messaging Program (IMP) 3.2.5

Quoting Chet Ramey <address@hidden>:

> > On Tue, 3 Apr 2007, Chet Ramey wrote:
> >
> > It is an interesting position for POSIX to take, given that in general
> > Unix is silent on success.
> It's the logical thing to do, considering the potential ambiguity that
> exists when you use a directory selected from CDPATH.  The illogical thing
> is that POSIX requires the output even when the shell is not interactive.
> > Does POSIX forbid an option "to turn this superfluous output off", as
> > Tony Balinski put it?
> Redirect stdout to /dev/null.  That's the conventional way to rid yourself
> of superfluous output.
This is where I find an inconsistency. With the function I gave,

  cd ()
    local oldd=$(pwd);
    local newd=$(command cd "$@" 2>/dev/null 1>&2 && pwd 2>/dev/null);
    echo oldd="<$oldd>";
    echo newd="<$newd>";
    if [[ $newd == "" ]]; then
        echo "cd $* failed" 1>&2;
        if [[ $oldd == $newd ]]; then
            echo "cd $* - no change" 1>&2;
            command cd "$@" 2> /dev/null 1>&2;

Running bash on Cygwin (taken from Cygwin):
    GNU bash, version 3.2.15(13)-release (i686-pc-cygwin)
    Copyright (C) 2005 Free Software Foundation, Inc.
the redirection in the assignment of newd for "command cd" doesn't work
(when cd generates output). I have a CDPATH=.:/home/tbalinski; now when I
use my cd function to go from MiscDocs to Dev (both in /home/tbalinski) I
  $ cd Dev
i.e. the newd variable was assigned both the output of cd (which should
have gone to /dev/null) and of the pwd that follows it, rather than just
the pwd. (I also tried "1>/dev/null 2>&1" for the redirects, same results).

Curiously, under the same conditions on a Red Hat Linux box:
    GNU bash, version 2.05b.0(1)-release (i386-redhat-linux-gnu)
    Copyright (C) 2002 Free Software Foundation, Inc.
I get the behaviour I expected: only one line in newd:
  $ cd Dev

Either something strange is going on with the Cygwin compatibility layer
or there is a problem with the later bash. Or am I writing my command



reply via email to

[Prev in Thread] Current Thread [Next in Thread]