I'm having trouble using grep, the returned results are n-empty, I mean without the 'n' character...This is the script sample :OLDIFS=$IFSIFS=\\ni=$(grep -ril $1 *)echo $iIFS=$OLDIFSI tried with IFS='\n' and IFS=\n but the result displays the correct pathes only when I get rid of the IFS...I'm using the result in a for theFile in $i; do......done loop, where the results are used in the right way and theFile is correctly displayed.The only problem is that I have no correct console/file output of $i, which is a strategic data :What I'm seeing in the console and the file which is written (sample) :LecteurSy dicatio _sy dic/fiche_93.xml What should be displayed and written (sample) :LecteurSyndication_syndic/fiche_93.xmlAny idea ?EDIT : complete script to play at home ;)#!/bin/bashmonTerminal=$(tty) ; monTerminal=${monTerminal:9}fichier=/home/importts/tmpCmdOpenFirst$monTerminal.xmlPWD=`pwd`echo == Recherche dans les fiches  == > $fichierecho Recherche : $1 >> $fichierecho Dans      : $PWD >> $fichierOLDIFS=$IFSIFS=\\ni=$(grep -ril $1 *)echo $iecho == Liste des fichiers trouves == >> $fichierecho $i >> $fichierIFS=$OLDIFS#while read uneFichefor uneFiche in $i;doecho ================================ >> $fichierecho == $uneFiche >> $fichierecho ================================ >> $fichierecho  >> $fichierxmlindent $uneFiche >> $fichierdone < /home/robert/tmpCmdOpenFirst_liste.txtnano $fichier#rm $fichier
Very strange behavior with grep and IFS
bash;shell script;grep;wildcards;quoting
First, you've set IFS to \n, not to a newline. In bash, you can use $'' to have backslash sequences interpreted as control characters:IFS=$'\n'Or you have the portable option of using a literal newline.IFS=''The second problem is that IFS matters when you expand a variable. So it needs to be set when $i is expanded, it doesn't actually matter when you set i.i=$(grep -ril -e $1 -- *)set -f; OLDIFS=$IFS; IFS=''for uneFiche in $i; do  set +f; IFS=$OLDIFS  doneset +f; IFS=$OLDIFSAdditionally, don't forget to quote variables when you aren't splitting, e.g. the pattern you pass to grep. In case the pattern starts with -, pass it to grep with the -e option. Also put -- in front of the file names in case the first file name begins with -. Furthermore, in case a file name contains glob characters, turn off globbing with set -f before leaving a variable expansion unquoted.A simpler approach would be to call grep on each file inside the loop. As an additional benefit, your script wouldn't break on file names containing newlines.for uneFiche in *; do  if grep -qri -e $1 -- $uneFiche; then      fidone