IFS is the internal field separator. The shell uses its value to determine word boundaries, that is, $IFS can be used to specify how words need to be split.
#!/bin/bash
#
# The default value of $IFS consists of a space,
# a tabulator and a new line.
# This can be shown with 'cat -A' which prints ^I for
# a tabulator and $ for a new linw
#
echo ">$IFS<" | cat -A
echo
# --------------------------------------------------------------
#
# Setting the IFS variable to specific character splits words
# on this character
IFS=:
for word in "one:two::three"; do
printf "word: %s\n" $word
done
echo
# This can of course be used to decompose the individual
# paths in $PATH
for path in $PATH; do
echo path=$path
done
echo
# --------------------------------------------------------------
#
# If IFS is set to +, the plus is "removed" (or split away) in
# an echo statement
IFS=+
var_plus='foo+bar+baz'
var_minus='foo-bar-baz'
echo $var_plus
echo $var_minus
echo
# --------------------------------------------------------------
#
# The space in IFS splits on one or more spaces.
IFS=" "
for word in "abc def ghijk"; do
printf "word: %s\n" $word
done
func() {
echo "This script has been running since $SECONDS second(s)"
}
func
sleep 1
func
sleep 2
func
sleep 3
func
# Output:
#
# This script has been running since 0 second(s)
# This script has been running since 1 second(s)
# This script has been running since 3 second(s)
# This script has been running since 6 second(s)