|
I was writing a bash script which has to loop over several folder recently. The command
for i in $( ls ); do ...
does that. However, if the folder or file names contain whitespaces then this wont work because the for loop splits the input at whitespaces. the reason for this is because for loop uses whatever is in the $IFS environment variable and uses that as the splitter characters. By default it is set to the space character. Thus we have to change this temporarily to a line break.
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
....
IFS=$SAVEIFS
For more details see here.
|