Bash Built-In Variables: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 11: Line 11:
==IFS==
==IFS==


<tt>IFS</tt> is the internal field separator. This variable determines how bash recognizes ''fields'' (word boundaries) when it interprets character strings. <tt>IFS</tt> defaults to whitespace (space, tab and newline) but maybe changed.
<tt>IFS</tt> is the internal field separator. This variable determines how bash recognizes ''fields'' (word boundaries) when it interprets character strings. <tt>IFS</tt> defaults to whitespace (space, tab and newline). This is the proof:
 
<pre>
echo "$IFS" | cat -vte
^I$
$
</pre>
 
<tt>IFS</tt> can be changed.


<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
<blockquote style="background-color: Gold; border: solid thin Goldenrod;">
:'''Note''' you must set IFS back to " " after setting it to something else, so the basic shell function work as expected. This is done with IFS=" ".<br>
:'''Note''' you must set IFS back to whitespace after setting it to something else, so the basic shell function work as expected. This is done with IFS=" ".<br>
</blockquote>
</blockquote>



Revision as of 00:06, 1 March 2016

External

Internal

Standard Environment Variables

IFS

IFS is the internal field separator. This variable determines how bash recognizes fields (word boundaries) when it interprets character strings. IFS defaults to whitespace (space, tab and newline). This is the proof:

echo "$IFS" | cat -vte
 ^I$
$

IFS can be changed.

Note you must set IFS back to whitespace after setting it to something else, so the basic shell function work as expected. This is done with IFS=" ".


IFS and for

for honors the value of IFS (default the space). If you set IFS to something else, for will use that as field separator while iterating over the list. For more details see for and IFS

Also see:

bash set List Separator