"Taking a LiveFire Labs' course is an excellent way to learn
Linux/Unix. The lessons are well thought out, the material is
explained thoroughly, and you get to perform exercises on a real
Linux/Unix box. It was money well spent."
Pembrook Pines, Florida
LiveFire Labs' UNIX and Linux Operating System Fundamentals
course was very enjoyable. Although I regularly used UNIX systems
for 16 years, I haven't done so since 2000. This course was a
great refresher. The exercises were fun and helped me gain a real
feel for working with UNIX/Linux OS. Thanks very much!"
Senior Technical Writer
Nuance Communications, Inc.
more student testimonials...
Receive UNIX Tips, Tricks, and Shell Scripts by Email
LiveFire Labs' UNIX Tip,
Trick, or Shell Script of the Week
Useful Shell Script Variables - Part III - IFS (Internal Field
Another shell script variable that you should become comfortable using
is the IFS, or internal field separator, variable. The shell uses the
value stored in IFS, which is the space, tab, and newline characters
by default, to delimit words for the read and set commands, when
parsing output from command substitution, and when performing variable
IFS can be redefined to parse one or more lines of data whose fields
are not delimited by the default white-space characters. Consider
this sequence of variable assignments and for loops:
$ for i in $line
> echo $i
$ for i in $line
> echo $i
The first command assigns the string “learn:unix:at:livefire:labs” to
the variable named line. You can see from the first for loop that the
shell treats the entire string as a single field. This is because the
string does not contain a space, tab, or newline character.
After redefining IFS, the second for loop treats the string as four
separated fields, each delimited by a colon. Using a colon for IFS
would be appropriate when parsing the fields in a record from
/etc/passwd, the user account information file:
Notice that the original value of IFS was stored in OIFS (“O” for
original) prior to changing its value. After you are finished using
the new definition, it would be wise to return it to its original
value to avoid unexpected side effects that may surface later on in
TIP – The current value of IFS may be viewed using the following
$ echo "$IFS" | od -b
0000000 040 011 012 012
The output of the echo command is piped into the octal dump command,
giving you its octal equivalent. You can then use an ASCII table to
determine what characters are stored in the variable. Hint:
Ignore the first set of zeros and the second newline character (012),
which was generated by echo.