popd
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
- popd [EN] @ GNU Bash Reference Manual
- bash -c 'help popd'
- man 1 'bash' [EN]
Syntax
popd
Examples
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
- ↑ bash -c 'help popd'