Используя предложение @ mikserv , вы можете сделать
cd /Test/TopDir/
set -- "$PWD" */
cd /somewhere/else
td=$1 ; shift
for x; do
echo x="${td}/$x"
done
popd
и pushd
— это команды, встроенные в Bash, они не являются настоящими исполняемыми файлами, которые живут на вашем жестком диске в виде настоящих двоичных файлов.
DIRSTACK
An array variable (see Arrays below) containing the current
contents of the directory stack. Directories appear in the stack
in the order they are displayed by the dirs builtin. Assigning to
members of this array variable may be used to modify directories
already in the stack, but the pushd and popd builtins must be used
to add and remove directories. Assignment to this variable will
not change the current directory. If DIRSTACK is unset, it loses
its special properties, even if it is subsequently reset.
Полный список всех встроенных команд доступен на справочной странице Bash, а также здесь-http://structure.usc.edu/bash/bashref_4.html.
Вы также можете использовать compgen -b
или enable
, чтобы получить полный список всех этих встроенных функций:
$ compgen -b | grep -E "^push|^pop"
popd
pushd
включить $ enable -a | grep -E "\bpop|\bpus"
enable popd
enable pushd
Кроме того, если вы хотите получить помощь по встроенным функциям, вы можете использовать команду help
:
$ help popd | head -5
popd: popd [-n] [+N | -N]
Remove directories from stack.
Removes entries from the directory stack. With no arguments, removes
the top directory from the stack, and changes to the new top directory.
$ help pushd | head -5
pushd: pushd [-n] [+N | -N | dir]
Add directories to stack.
Adds a directory to the top of the directory stack, or rotates
the stack, making the new top of the stack the current working