bash script use IFS in context of for looping

How to use bash script 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
#!/bin/bash
#Author: HuuPV

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
[huupv@huupv Downloads]$ ./IFS_test.sh

The display as below:
Values in huu:phan linux operating,system -
 huu
 phan
 linux
 operating
 system
bash script use IFS in context of for looping

Comments

Popular posts from this blog

zimbra some services are not running [Solve problem]

Bash script list all IP addresses connected to Server

How to install php7 on centos 6