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 inIFS
variable take place? – Martin Jun 16 '15 at 07:19echo '$IFS'
result will be$IFS
. – taliezin Jun 16 '15 at 07:26IFS="blah" echo $IFS
orIFS=x VAR="abcxklm" echo $VAR
orIFS=x VAR="abcx" echo $VAR | sed -n l
then I would think that word-splitting is substituting characters in expanded variable with space ifIFS
character(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 $list
andfor i in "$list"
will produce different results. – taliezin Jun 16 '15 at 09:07