Bash Built-In Variables: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
No edit summary
Line 6: Line 6:


==IFS==
==IFS==
==List Separator==
The default list separator is space. That can be changed by setting the value of the <tt>IFS</tt> variable before executing <tt>set</tt>.
Example:
<pre>
arg="a,b,c"
IFS=","
set ${arg}
</pre>
will identically assign "a", "b", "c" to positional parameters $1, $2 and $3.
<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>
</blockquote>

Revision as of 23:35, 29 February 2016

Internal

Standard Environment Variables

IFS

List Separator

The default list separator is space. That can be changed by setting the value of the IFS variable before executing set.

Example:

arg="a,b,c"
IFS=","
set ${arg}

will identically assign "a", "b", "c" to positional parameters $1, $2 and $3.

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=" ".