Huu Phan | Blog Linux operating system | Linux operating system -Blog Huu Phan | www.huuphan.com
huuphan.com. Powered by Blogger.

bash script use IFS in context of for looping

My post, How to bash script use IFS in context of for looping
what does IFS meaning?
The IFS stands for "internal Field separator", that is used how to do word splitting.
IFS is a special shell variable. The used for looping in context of file.
bash script use IFS in context of for looping


The bash script
#!/bin/bash
IFSOLD=$IFS
IFS=$'\n':,' '
for entry in "huu:phan linux operating,system"
do
        echo "Values in $entry -"
        #IFS=': ,'
        for value in $entry
        do
                echo " $value"
        done
done
IFS=$IFSOLD

Running bash script use IFS in context of for looping
[[email protected] Downloads]$ ./IFS_test.sh
As the output bellow
Values in huu:phan linux operating,system -
 huu
 phan
 linux
 operating
 system

post new :

Huu Phan | Blog Linux operating system | Huu Phan ~ Zimbra Mail Server,linux,bash script,centos,linux command | www.huuphan.com