popd always has return status 0

2011-12-02 Thread james . cuzella
Configuration Information [Automatically generated, do not change]:
Machine: x86_64
OS: linux-gnu
Compiler: gcc
Compilation CFLAGS:  -DPROGRAM='bash' -DCONF_HOSTTYPE='x86_64' 
-DCONF_OSTYPE='linux-gnu' -DCONF_MACHTYPE='x86_64-pc-linux-gnu' 
-DCONF_VENDOR='pc' -DLOCALEDIR='/usr/share/locale' -DPACKAGE='bash' -DSHELL 
-DHAVE_CONFIG_H   -I.  -I../bash -I../bash/include -I../bash/lib   -g -O2 -Wall
uname output: Linux cirrus 3.0.0-13-generic #22-Ubuntu SMP Wed Nov 2 13:27:26 
UTC 2011 x86_64 x86_64 x86_64 GNU/Linux
Machine Type: x86_64-pc-linux-gnu

Bash Version: 4.2
Patch Level: 10
Release Status: release

Description:
popd does not appear to return a nonzero exit status when the directory 
stack is empty anymore.  The bash manual says the following for popd:

"If the popd command is successful, a dirs is performed as well, and 
the return status is 0.  popd returns false if an invalid option is 
encountered, the directory stack is
  empty, a non-existent directory stack entry is specified, 
or the directory change fails."
  
I am seeing this problem on: Ubuntu 11.10 oneiric
   bash package version: 4.2-0ubuntu4

Repeat-By:
Put some directories on the stack with pushd, then call popd and check 
the return status.  It is expected to be nonzero when the stack is empty or an 
error occurs.
The following function should pop all dirs off the stack and then stop, 
however the while loop continues infinitely:

popall () 
{ 
local not_done=0;
while [ $not_done -eq 0 ]; do
popd;
not_done=$?;
done
}



Re: popd always has return status 0

2012-10-22 Thread James Cuzella
It seems that RVM is the source of the problem.  It overrides the
popdbuiltin with a function:

$ type popd
popd is a function
popd ()
{
builtin popd;
if [[ -s "$PWD/.rvmrc" ]]; then
source "$PWD/.rvmrc";
fi
}

So it looks like this is really a bug in RVM.  Thanks for the help finding
the cause of this one... without someone else able to reproduce, it made me
take a second look at it ;-)

- James

On Sat, Dec 3, 2011 at 12:06 AM, Mike Frysinger  wrote:

> On Thursday 01 December 2011 19:01:50 james.cuze...@lyraphase.com wrote:
> > Description:
> >   popd does not appear to return a nonzero exit status when the
> directory
> > stack is empty anymore.
>
> works for me:
> $ echo $BASH_VERSION ; popd ; echo $?
> 4.2.20(1)-release
> bash: popd: directory stack empty
> 1
>
> as does your popall func
> -mike
>