Ifs=$'\\n' what is the meaning behind this collection of symbols? 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. I was reading this q&a How to loop over the lines of a file
What is the ifs variable Using var=value cmd syntax makes sure ifs / lc_all are only set differently for the duration of that cmd command History note the read builtin was introduced by the bourne shell and was already to read words, not lines There are a few important differences with modern posix shells. Or more generally, contains a space Cat${ifs}file.txt the default value of ifs is space, tab, newline
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. 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). Changing ifs temporarily before a for loop [duplicate] ask question asked 5 years, 2 months ago modified 4 years, 7 months ago
An example may explain the issue more clea. 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). 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 "$*" Is handled), and then restore the original value of i.
WATCH