[Top][All Lists]

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

inconsistent output for cd

From: Tony Balinski
Subject: inconsistent output for cd
Date: Mon, 02 Apr 2007 11:01:48 -0400
User-agent: Internet Messaging Program (IMP) 3.2.5

Configuration Information [Automatically generated, do not change]:
Machine: i686
OS: cygwin
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash.exe' -DCONF_HOSTTYPE='i686'
-DCONF_OSTYPE='cygwin' -DCONF_MACHTYPE='i686-pc-cygwin' -DCONF_VENDOR='pc'
-DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL -DHAVE_CONFIG_H
-DRECYCLES_PIDS   -I.  -I/home/eblake/bash-3.2.15-13/src/bash-3.2
-I/home/eblake/bash-3.2.15-13/src/bash-3.2/lib   -O2 -pipe
uname output: CYGWIN_NT-5.1 nycutbalil 1.5.24(0.156/4/2) 2007-01-31 10:57 i686
Machine Type: i686-pc-cygwin

Bash Version: 3.2
Patch Level: 15
Release Status: release

    Sometimes cd echos the new directory, sometimes it doesn't. This makes
    picking up a new directory in an overridden cd function painful:
        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
            elif [[ $oldd == $newd ]]; then
                echo "cd $* - no change" 1>&2
                # do extra cd processing here
                command cd "$@" 2>/dev/null 1>&2
                # do extra cd processing here
    In the assignment of newd, curiously, we get either one line or two!
    newd should be just the new directory (the result of running built-in
    cd in a subshell) but since it sometimes outputs a result (which seems
    to bypass the output redirection), newd may end up with two separate
    directories in two lines.

    It seems like this extra output only occurs when CDPATH is used for the
    cd operation. Also, popd and pushd also have similarly inconvenient
    outputs. None of this is documented in the manual, and there appear to
    be no options at all to turn this superfluous output off.

    Try the above function, with the commented lines uncommented. Use it
    to change to a directory in the CDPATH. Check the newd=... output.

    Don't use CDPATH! But that's a shame...

reply via email to

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