diff options
Diffstat (limited to 'devdocs/bash/tilde-expansion.html')
| -rw-r--r-- | devdocs/bash/tilde-expansion.html | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/devdocs/bash/tilde-expansion.html b/devdocs/bash/tilde-expansion.html new file mode 100644 index 00000000..de64123d --- /dev/null +++ b/devdocs/bash/tilde-expansion.html @@ -0,0 +1,12 @@ +<h1 class="subsection">Tilde Expansion</h1> <p>If a word begins with an unquoted tilde character (‘<samp>~</samp>’), all of the characters up to the first unquoted slash (or all characters, if there is no unquoted slash) are considered a <em>tilde-prefix</em>. If none of the characters in the tilde-prefix are quoted, the characters in the tilde-prefix following the tilde are treated as a possible <em>login name</em>. If this login name is the null string, the tilde is replaced with the value of the <code>HOME</code> shell variable. If <code>HOME</code> is unset, the home directory of the user executing the shell is substituted instead. Otherwise, the tilde-prefix is replaced with the home directory associated with the specified login name. </p> <p>If the tilde-prefix is ‘<samp>~+</samp>’, the value of the shell variable <code>PWD</code> replaces the tilde-prefix. If the tilde-prefix is ‘<samp>~-</samp>’, the value of the shell variable <code>OLDPWD</code>, if it is set, is substituted. </p> <p>If the characters following the tilde in the tilde-prefix consist of a number <var>N</var>, optionally prefixed by a ‘<samp>+</samp>’ or a ‘<samp>-</samp>’, the tilde-prefix is replaced with the corresponding element from the directory stack, as it would be displayed by the <code>dirs</code> builtin invoked with the characters following tilde in the tilde-prefix as an argument (see <a href="the-directory-stack">The Directory Stack</a>). If the tilde-prefix, sans the tilde, consists of a number without a leading ‘<samp>+</samp>’ or ‘<samp>-</samp>’, ‘<samp>+</samp>’ is assumed. </p> <p>If the login name is invalid, or the tilde expansion fails, the word is left unchanged. </p> <p>Each variable assignment is checked for unquoted tilde-prefixes immediately following a ‘<samp>:</samp>’ or the first ‘<samp>=</samp>’. In these cases, tilde expansion is also performed. Consequently, one may use filenames with tildes in assignments to <code>PATH</code>, <code>MAILPATH</code>, and <code>CDPATH</code>, and the shell assigns the expanded value. </p> <p>The following table shows how Bash treats unquoted tilde-prefixes: </p> <dl compact> <dt><span><code>~</code></span></dt> <dd><p>The value of <code>$HOME</code> </p></dd> <dt><span><code>~/foo</code></span></dt> <dd> +<p><samp>$HOME/foo</samp> </p> </dd> <dt><span><code>~fred/foo</code></span></dt> <dd> +<p>The subdirectory <code>foo</code> of the home directory of the user <code>fred</code> </p> </dd> <dt><span><code>~+/foo</code></span></dt> <dd> +<p><samp>$PWD/foo</samp> </p> </dd> <dt><span><code>~-/foo</code></span></dt> <dd> +<p><samp>${OLDPWD-'~-'}/foo</samp> </p> </dd> <dt><span><code>~<var>N</var></code></span></dt> <dd> +<p>The string that would be displayed by ‘<samp>dirs +<var>N</var></samp>’ </p> </dd> <dt><span><code>~+<var>N</var></code></span></dt> <dd> +<p>The string that would be displayed by ‘<samp>dirs +<var>N</var></samp>’ </p> </dd> <dt><span><code>~-<var>N</var></code></span></dt> <dd><p>The string that would be displayed by ‘<samp>dirs -<var>N</var></samp>’ </p></dd> </dl> <p>Bash also performs tilde expansion on words satisfying the conditions of variable assignments (see <a href="shell-parameters">Shell Parameters</a>) when they appear as arguments to simple commands. Bash does not do this, except for the declaration commands listed above, when in <small>POSIX</small> mode. </p><div class="_attribution"> + <p class="_attribution-p"> + Copyright © 2000, 2001, 2002, 2007, 2008 Free Software Foundation, Inc.<br>Licensed under the GNU Free Documentation License.<br> + <a href="https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Tilde-Expansion.html</a> + </p> +</div> |
