I have set the IFS to x, i.e IFS=x. Now if I check the value of IFS, then it appears to be empty if I do not use double-quotes:
~ $ echo $IFS | cat -e
$
~ $ echo "$IFS" | cat -e
x$
~ $ echo $HOME
/home/mar
~ $ echo "$HOME"
/home/mar
~ $
As seen above, $HOME does not behave like that. What is the reason for such behavior?
echo, then there is no word-splitting and this single argument is passed toecho. So am I correct that if I don't use double-quotes around the variable name then word-splitting based on characters inIFSvariable take place? – Martin Jun 16 '15 at 07:19echo '$IFS'result will be$IFS. – taliezin Jun 16 '15 at 07:26IFS="blah" echo $IFSorIFS=x VAR="abcxklm" echo $VARorIFS=x VAR="abcx" echo $VAR | sed -n lthen I would think that word-splitting is substituting characters in expanded variable with space ifIFScharacter(s) is in the middle of the string and with nothing if no other characters follow? – Martin Jun 16 '15 at 08:36list="koko moko"and thenfor i in $listandfor i in "$list"will produce different results. – taliezin Jun 16 '15 at 09:07