Quote:
Originally Posted by
kristinu
Or I am messing things up at this point, and the only thing that matters is that arguments are now in $1, $2, ...?
Yes, exactly. IFS does not control what $1 $2 ... do -- it controls what an unquoted $ does. So we split
once, setting the $1 $2 ... variables to exactly what we want, and can expect them to remain that way no matter what we do to IFS afterwards.
Quote:
Why does it smash everything with |. Is that standard or is it because I used | as the first character in IFS?
It's because it's the first character in IFS.
By default, that is space, so if you didn't change IFS, $* would give you "arg1 arg2 arg3 arg4" instead of "arg1|arg2|arg3|arg4".
See what I mean about it not being what you expected? You expected that $* gives you the same arguments you passed into the script. It never did, it
always squashes $1 $2 ... together -- it just
looked like your arguments because IFS defaults to space. (Well, space and tab and newline, but you get the idea.)
Quote:
I am sure that if I use IFS="F=", instead of having |, I will have 'F' being displayed when the arguments are smashed together.
Yes, exactly. I picked | because it's unlikely to be used in your arguments, but could have as easily used 'e', '@', '^', or any other ASCII character. Don't use * or ?, since the shell will try to glob on those. (like what happens when you do
ls *.jpg)
It's important that it not be in your input, because IFS="F=" would split "--arg=Fast" into $1="--arg", and $2="ast" !