Skip to main content
fix 2 word-breaks
Source Link
Jeff Schaller
  • 68.8k
  • 35
  • 122
  • 266

In Bash, word splitting is a step in command line processing. From Bash Manual

The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words using these characters as fi eldfield terminators. If IFS is unset, or its value is exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a fi eldfield. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.

I want to rewrite the following example, so that the delimiter space between the arguments a, b and c is replaced with tab or newline

$ echo a b c a b c 

But when I hit the key Tab, there is no response.

When I hit \ and return, there is no space between a, b and c in the output:

$ echo a\ > b\ > c abc 

Why can't I do what the quote says?

Btw, nothing comes out of $IFS:

$ echo $IFS 

In Bash, word splitting is a step in command line processing. From Bash Manual

The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words using these characters as fi eld terminators. If IFS is unset, or its value is exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a fi eld. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.

I want to rewrite the following example, so that the delimiter space between the arguments a, b and c is replaced with tab or newline

$ echo a b c a b c 

But when I hit the key Tab, there is no response.

When I hit \ and return, there is no space between a, b and c in the output:

$ echo a\ > b\ > c abc 

Why can't I do what the quote says?

Btw, nothing comes out of $IFS:

$ echo $IFS 

In Bash, word splitting is a step in command line processing. From Bash Manual

The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words using these characters as field terminators. If IFS is unset, or its value is exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a field. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.

I want to rewrite the following example, so that the delimiter space between the arguments a, b and c is replaced with tab or newline

$ echo a b c a b c 

But when I hit the key Tab, there is no response.

When I hit \ and return, there is no space between a, b and c in the output:

$ echo a\ > b\ > c abc 

Why can't I do what the quote says?

Btw, nothing comes out of $IFS:

$ echo $IFS 
Source Link
Tim
  • 106.9k
  • 234
  • 651
  • 1.1k

Delimiter in word splitting

In Bash, word splitting is a step in command line processing. From Bash Manual

The shell treats each character of $IFS as a delimiter, and splits the results of the other expansions into words using these characters as fi eld terminators. If IFS is unset, or its value is exactly <space><tab><newline>, the default, then sequences of <space>, <tab>, and <newline> at the beginning and end of the results of the previous expansions are ignored, and any sequence of IFS characters not at the beginning or end serves to delimit words. If IFS has a value other than the default, then sequences of the whitespace characters space and tab are ignored at the beginning and end of the word, as long as the whitespace character is in the value of IFS (an IFS whitespace character). Any character in IFS that is not IFS whitespace, along with any adjacent IFS whitespace characters, delimits a fi eld. A sequence of IFS whitespace characters is also treated as a delimiter. If the value of IFS is null, no word splitting occurs.

I want to rewrite the following example, so that the delimiter space between the arguments a, b and c is replaced with tab or newline

$ echo a b c a b c 

But when I hit the key Tab, there is no response.

When I hit \ and return, there is no space between a, b and c in the output:

$ echo a\ > b\ > c abc 

Why can't I do what the quote says?

Btw, nothing comes out of $IFS:

$ echo $IFS