popd

From RaySoft

Removes entries from the directory stack. With no arguments, removes the top directory from the stack, and changes to the new top directory.[1]

Documentation

Syntax

popd

Examples

Redefine cd to use pushd and popd
my::_cd() {
  # Provide a 'cd' command replacement using 'pushd'.
  #
  # Arguments:
  #   $1: Path (optional)
  #
  # Returns:
  #   0:  Success
  #   >0: Error

  if [[ "$#" -eq 0 ]]; then
    set -- "${HOME}"
  fi

  if [[ ! -d "$1" ]]; then
    echo "Error finding directory: $1!"
    return 1
  fi

  if ! pushd "$1" >'/dev/null' 2>&1; then
    echo "Error changing directory: $1!"
    return 1
  fi

  return 0
}
alias -- -='popd >"/dev/null" 2>&1'

if declare -F my::_cd >'/dev/null' 2>&1; then
  alias cd='my::_cd'
fi

References

  1. bash -c 'help popd'