Understanding IFS= read -r line - Unix Linux Stack Exchange So when doing IFS= read -r line, what you are doing is setting IFS to an empty string (no character will be used to split, therefore no splitting will occur) so that read will read the entire line and see it as one word that will be assigned to the line variable
shell - Understanding IFS - Unix Linux Stack Exchange The following few threads on this site and StackOverflow were helpful for understanding how IFS works: What is IFS in context of for looping? How to loop over the lines of a file Bash, read line by
For loop over lines -- how to set IFS only for one `for` statement? We change IFS and may forget to restore it We restore IFS every single iteration of the loop I discovered that while IFS= can be used here like that: But this is not an option because read -p prompt gets corrupted by continuous input stream A solution would be IFS set only for one for statement like this: but bash disallows that
How to temporarily save and restore the IFS variable properly? How do I correctly run a few commands with an altered value of the IFS variable (to change the way field splitting works and how quot;$* quot; is handled), and then restore the original value of I
Why is `while IFS= read` used so often, instead of `IFS=; while read. . `? The IFS= read -r line sets the environment variable IFS (to an empty value) specifically for the execution of read This is an instance of the general simple command syntax: a (possibly empty) sequence of variable assignments followed by a command name and its arguments (also, you can throw in redirections at any point)
understanding the default value of IFS - Unix Linux Stack Exchange Here if the expansion contains any IFS characters, then it split into different 'words' before the command is processed Effectively this means that these characters split the substituted text into different arguments (including the name of the command if the variable is specified first)
How to send a command with arguments without spaces? If only there was a variable whose value is a space… Or more generally, contains a space cat${IFS}file txt The default value of IFS is space, tab, newline All of these characters are whitespace If you need a single space, you can use ${IFS%??} More precisely, the reason this works has to do with how word splitting works Critically, it's applied after substituting the value of variables
Is it a sane approach to back up the $IFS variable? Implementations may ignore the value of IFS in the environment, or the absence of IFS from the environment, at the time the shell is invoked, in which case the shell shall set IFS to <space> <tab> <newline> when it is invoked A POSIX-compliant, invoked shell may or may not inherit IFS from its environment From this follows: