Skip to main content
deleted 56 characters in body
Source Link
Peyman Mohamadpour
  • 18k
  • 24
  • 94
  • 102

Question:

What is the exact meaning of IFS=$'\n'?

Simple Answer:

Hey Bash! set the Internal Field Separator (IFS) to New Line


What is IFS ?

IFS is the character, Bash uses as word/item boundaries when processing character strings.

It is set to whitespace characters of space, tab, and newline, by default.

Example 1:

Use default value for IFS

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first
second:third
forth:fifth

Example 2:

Set IFS to :

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first second  
third forth  
fifth

Question:

What is the exact meaning of IFS=$'\n'?

Simple Answer:

Hey Bash! set the Internal Field Separator (IFS) to New Line


What is IFS ?

IFS is the character, Bash uses as word/item boundaries when processing character strings.

It is set to whitespace characters of space, tab, and newline, by default.

Example 1:

Use default value for IFS

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first
second:third
forth:fifth

Example 2:

Set IFS to :

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first second  
third forth  
fifth

Question:

What is the exact meaning of IFS=$'\n'?

Simple Answer:

Hey Bash! set the Internal Field Separator (IFS) to New Line


What is IFS ?

IFS is the character, Bash uses as word/item boundaries when processing character strings.

It is set to whitespace characters of space, tab, and newline, by default.

Example 1:

Use default value for IFS

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first
second:third
forth:fifth

Example 2:

Set IFS to :

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first second  
third forth  
fifth
Source Link
Peyman Mohamadpour
  • 18k
  • 24
  • 94
  • 102

Question:

What is the exact meaning of IFS=$'\n'?

Simple Answer:

Hey Bash! set the Internal Field Separator (IFS) to New Line


What is IFS ?

IFS is the character, Bash uses as word/item boundaries when processing character strings.

It is set to whitespace characters of space, tab, and newline, by default.

Example 1:

Use default value for IFS

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first
second:third
forth:fifth

Example 2:

Set IFS to :

# Set the IFS to collon (:) character
IFS=:

string="first second:third forth:fifth"

for item in $string; do
    echo "$item"
done

Output:

first second  
third forth  
fifth