List of Topics
1) What is IFS
2) Use of IFS
3) Example for IFS
1) What is IFS
FS variable
is commonly used with read command, parameter expansions and command
substitution. Internal field separator refers to a variable which
defines the character or characters used to separate a pattern. The shell treats each
character of $IFS as a delimiter, and splits the result. If IFS has a value other than the
default (space, tab), then sequences of the whitespace characters space and tab are ignored.
2) Use of IFS
IFS will be useful when we need a read a file which is having delimiter other than default space/tab. Below is the example for IFS which will give you more clarifications. In case of any queries please post in comment will try to help you.
3) Example of IFS
Below is the one of the case of IFS. Like this we can use IFS in many places while working with shell script.
[user@test XXXXX]$ cat
file1
gmis_production/linux_production_apps/MIA ARA
When we read the above file with for loop, it will consider till MIA in the last as
"1" input and ARA as 2nd input. To avoid this and to tell for loop not
to consider spaces in line as delimiter and only new line is the delimiter then we need to use IFS variable.
eg : IFS=$'\n'
for FNAME in `cat $SRCFLDR/AVLFILES
do
echo $FNAME
done
List of Topics
1) What is IFS
FS variable is commonly used with read command, parameter expansions and command substitution. Internal field separator refers to a variable which defines the character or characters used to separate a pattern. The shell treats each character of $IFS as a delimiter, and splits the result. If IFS has a value other than the default (space, tab), then sequences of the whitespace characters space and tab are ignored.
1) What is IFS
2) Use of IFS
3) Example for IFS
FS variable is commonly used with read command, parameter expansions and command substitution. Internal field separator refers to a variable which defines the character or characters used to separate a pattern. The shell treats each character of $IFS as a delimiter, and splits the result. If IFS has a value other than the default (space, tab), then sequences of the whitespace characters space and tab are ignored.
2) Use of IFS
IFS will be useful when we need a read a file which is having delimiter other than default space/tab. Below is the example for IFS which will give you more clarifications. In case of any queries please post in comment will try to help you.
3) Example of IFS
Below is the one of the case of IFS. Like this we can use IFS in many places while working with shell script.
[user@test XXXXX]$ cat
file1
gmis_production/linux_production_apps/MIA ARA
When we read the above file with for loop, it will consider till MIA in the last as "1" input and ARA as 2nd input. To avoid this and to tell for loop not to consider spaces in line as delimiter and only new line is the delimiter then we need to use IFS variable.
eg : IFS=$'\n'
for FNAME in `cat $SRCFLDR/AVLFILES
do
echo $FNAME
done
No comments:
Post a Comment