pushd
Adds a directory to the top of the directory stack, or rotates the stack, making the new top of the stack the current working directory. With no arguments, exchanges the top two directories.[1]
Documentation
- pushd [EN] @ GNU Bash Reference Manual
- bash -c 'help pushd'
- man 1 'bash' [EN]
Syntax
pushd [DIRECTORY]
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 pushd'