To be more clear, let's create a script named showarg
:
#!/usr/bin/env bash
printf "%d args:" $#
printf " <%s>" "$@"
echo
Now let's see the differences:
$ var="This is an example"
$ showarg $var
4 args: <This> <is> <an> <example>
$var
is split into 4 args.IFS
is white space characters and thus word splitting occurred in spaces
$ var="This/is/an/example"
$ showarg $var
1 args: <This/is/an/example>
In above word splitting didn't occur because the
IFS
characters weren't found.
Now let's set IFS=/
$ IFS=/
$ var="This/is/an/example"
$ showarg $var
4 args: <This> <is> <an> <example>
The
$var
is splitting into 4 arguments not a single argument.