Bash set: Difference between revisions
Jump to navigation
Jump to search
No edit summary |
|||
Line 39: | Line 39: | ||
<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 | :'''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 as shown below: [[bash Environment Variables#Restoring_the_default_IFS_value|restoring the default IFS value]].<br> | ||
</blockquote> | </blockquote> | ||
Revision as of 00:08, 1 March 2016
External
- set man page http://linuxcommand.org/lc3_man_pages/seth.html
Internal
set and Positional Parameters
arg="a b c" set ${arg}
assigns "a", "b", "c" to positional parameters $1, $2 and $3.
Note that if any of the space-separated argument contains '--', set will try to interpret that sequence of characters:
set: --: invalid option
so in order to turn it back into positional argument, you will have to ??? do something, did not figure it out yet.
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 whitespace after setting it to something else, so the basic shell function work as expected. This is done as shown below: restoring the default IFS value.
For more details about IFS see: