summaryrefslogtreecommitdiff
path: root/devdocs/bash/word-splitting.html
blob: 39bc6fe902f474ee8bc6b2aab672b7e51b4a91bb (plain)
1
2
3
4
5
6
<h1 class="subsection">Word Splitting</h1>  <p>The shell scans the results of parameter expansion, command substitution, and arithmetic expansion that did not occur within double quotes for word splitting. </p> <p>The shell treats each character of <code>$IFS</code> as a delimiter, and splits the results of the other expansions into words using these characters as field terminators. If <code>IFS</code> is unset, or its value is exactly <code>&lt;space&gt;&lt;tab&gt;&lt;newline&gt;</code>, the default, then sequences of <code> &lt;space&gt;</code>, <code>&lt;tab&gt;</code>, and <code>&lt;newline&gt;</code> at the beginning and end of the results of the previous expansions are ignored, and any sequence of <code>IFS</code> characters not at the beginning or end serves to delimit words. If <code>IFS</code> has a value other than the default, then sequences of the whitespace characters <code>space</code>, <code>tab</code>, and <code>newline</code> are ignored at the beginning and end of the word, as long as the whitespace character is in the value of <code>IFS</code> (an <code>IFS</code> whitespace character). Any character in <code>IFS</code> that is not <code>IFS</code> whitespace, along with any adjacent <code>IFS</code> whitespace characters, delimits a field. A sequence of <code>IFS</code> whitespace characters is also treated as a delimiter. If the value of <code>IFS</code> is null, no word splitting occurs. </p> <p>Explicit null arguments (<code>""</code> or <code>''</code>) are retained and passed to commands as empty strings. Unquoted implicit null arguments, resulting from the expansion of parameters that have no values, are removed. If a parameter with no value is expanded within double quotes, a null argument results and is retained and passed to a command as an empty string. When a quoted null argument appears as part of a word whose expansion is non-null, the null argument is removed. That is, the word <code>-d''</code> becomes <code>-d</code> after word splitting and null argument removal. </p> <p>Note that if no expansion occurs, no splitting is performed. </p><div class="_attribution">
  <p class="_attribution-p">
    Copyright &copy; 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/Word-Splitting.html" class="_attribution-link">https://www.gnu.org/software/bash/manual/html_node/Word-Splitting.html</a>
  </p>
</div>