Bash Directory Manipulation Built-in Commands: Difference between revisions
(→popd) |
|||
(8 intermediate revisions by the same user not shown) | |||
Line 9: | Line 9: | ||
=<span id='DIRSTACK'></span><tt>DIRSTACK</tt> Environment Variable= | =<span id='DIRSTACK'></span><tt>DIRSTACK</tt> Environment Variable= | ||
<code>DIRSTACK </code> is an array variable that contains the current contents of the [[#Directory_Stack|directory stack]]. Directories appear in the stack in the order they are displayed by the <code>[[#dirs|dirs]]</code> builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the <code>[[#pushd|pushd]]</code> and <code>[[#popd|popd]]</code> builtins must be used to add and remove directories. Assignment to this variable will not change the current directory. If <code>DIRSTACK </code> is unset, it loses its special properties, even if it is subsequently reset. | <code>DIRSTACK</code> is an array variable that contains the current contents of the [[#Directory_Stack|directory stack]]. Directories appear in the stack in the order they are displayed by the <code>[[#dirs|dirs]]</code> builtin. Assigning to members of this array variable may be used to modify directories already in the stack, but the <code>[[#pushd|pushd]]</code> and <code>[[#popd|popd]]</code> builtins must be used to add and remove directories. Assignment to this variable will not change the current directory. If <code>DIRSTACK</code> is unset, it loses its special properties, even if it is subsequently reset. | ||
=Commands= | =Commands= | ||
==<tt>dirs</tt>== | ==<tt>dirs</tt>== | ||
==<tt>pushd</tt>== | ==<tt>pushd</tt>== | ||
Change the current directory to the given directory, while saving the current working directory on the directory stack. Dump the stack at <code>stdout</code>. | |||
To get rid of the stdout, direct it to <code>/dev/null</code>. | |||
<syntaxhighlight lang='bash'> | |||
pushd ${d} >/dev/null | |||
</syntaxhighlight> | |||
==<tt>popd</tt>== | ==<tt>popd</tt>== | ||
Change the current directory to the directory saved on the top of the stack. Dump the stack at <code>stdout</code>. | |||
To get rid of the stdout, direct it to <code>/dev/null</code>. | |||
<syntaxhighlight lang='bash'> | |||
popd >/dev/null | |||
</syntaxhighlight> |
Latest revision as of 23:22, 1 February 2022
Internal
Overview
pushd
and popd
are bash built commands.
Concepts
Directory Stack
DIRSTACK Environment Variable
DIRSTACK
is an array variable that contains 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.
Commands
dirs
pushd
Change the current directory to the given directory, while saving the current working directory on the directory stack. Dump the stack at stdout
.
To get rid of the stdout, direct it to /dev/null
.
pushd ${d} >/dev/null
popd
Change the current directory to the directory saved on the top of the stack. Dump the stack at stdout
.
To get rid of the stdout, direct it to /dev/null
.
popd >/dev/null