What does $IFS$() mean? [closed]












1















Just as the title states, I'm confused about $IFS$(), I saw it in a website which said that $IFS$() can replace the blank space, but I don't know how. Can anyone help me?










share|improve this question















closed as off-topic by kvantour, Matthieu Brucher, usr, Socowi, Machavity Nov 23 '18 at 16:01


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – kvantour, Matthieu Brucher, usr, Socowi, Machavity

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Could you point us to that website, to get some more context?

    – kvantour
    Nov 23 '18 at 12:50











  • of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

    – anonymous
    Nov 23 '18 at 12:56











  • From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

    – 9769953
    Nov 23 '18 at 12:59











  • $() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

    – 9769953
    Nov 23 '18 at 13:02






  • 1





    From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

    – kvantour
    Nov 23 '18 at 13:08


















1















Just as the title states, I'm confused about $IFS$(), I saw it in a website which said that $IFS$() can replace the blank space, but I don't know how. Can anyone help me?










share|improve this question















closed as off-topic by kvantour, Matthieu Brucher, usr, Socowi, Machavity Nov 23 '18 at 16:01


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – kvantour, Matthieu Brucher, usr, Socowi, Machavity

If this question can be reworded to fit the rules in the help center, please edit the question.

















  • Could you point us to that website, to get some more context?

    – kvantour
    Nov 23 '18 at 12:50











  • of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

    – anonymous
    Nov 23 '18 at 12:56











  • From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

    – 9769953
    Nov 23 '18 at 12:59











  • $() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

    – 9769953
    Nov 23 '18 at 13:02






  • 1





    From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

    – kvantour
    Nov 23 '18 at 13:08
















1












1








1








Just as the title states, I'm confused about $IFS$(), I saw it in a website which said that $IFS$() can replace the blank space, but I don't know how. Can anyone help me?










share|improve this question
















Just as the title states, I'm confused about $IFS$(), I saw it in a website which said that $IFS$() can replace the blank space, but I don't know how. Can anyone help me?







bash shell






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 23 '18 at 13:32









xSavitar

748826




748826










asked Nov 23 '18 at 12:36









anonymousanonymous

306




306




closed as off-topic by kvantour, Matthieu Brucher, usr, Socowi, Machavity Nov 23 '18 at 16:01


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – kvantour, Matthieu Brucher, usr, Socowi, Machavity

If this question can be reworded to fit the rules in the help center, please edit the question.







closed as off-topic by kvantour, Matthieu Brucher, usr, Socowi, Machavity Nov 23 '18 at 16:01


This question appears to be off-topic. The users who voted to close gave this specific reason:


  • "This question was caused by a problem that can no longer be reproduced or a simple typographical error. While similar questions may be on-topic here, this one was resolved in a manner unlikely to help future readers. This can often be avoided by identifying and closely inspecting the shortest program necessary to reproduce the problem before posting." – kvantour, Matthieu Brucher, usr, Socowi, Machavity

If this question can be reworded to fit the rules in the help center, please edit the question.













  • Could you point us to that website, to get some more context?

    – kvantour
    Nov 23 '18 at 12:50











  • of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

    – anonymous
    Nov 23 '18 at 12:56











  • From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

    – 9769953
    Nov 23 '18 at 12:59











  • $() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

    – 9769953
    Nov 23 '18 at 13:02






  • 1





    From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

    – kvantour
    Nov 23 '18 at 13:08





















  • Could you point us to that website, to get some more context?

    – kvantour
    Nov 23 '18 at 12:50











  • of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

    – anonymous
    Nov 23 '18 at 12:56











  • From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

    – 9769953
    Nov 23 '18 at 12:59











  • $() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

    – 9769953
    Nov 23 '18 at 13:02






  • 1





    From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

    – kvantour
    Nov 23 '18 at 13:08



















Could you point us to that website, to get some more context?

– kvantour
Nov 23 '18 at 12:50





Could you point us to that website, to get some more context?

– kvantour
Nov 23 '18 at 12:50













of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

– anonymous
Nov 23 '18 at 12:56





of course, but it's a Russia website antichat.com/threads/463395/#post-4254681

– anonymous
Nov 23 '18 at 12:56













From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

– 9769953
Nov 23 '18 at 12:59





From unix.stackexchange.com/questions/184863/…: internal field separator. With explanation in that answer. And as stated in that answer: "The default value for IFS consists of whitespace characters (to be precise: space, tab and newline).". Hence it can replace a (blank) space, as well as a few other characters.

– 9769953
Nov 23 '18 at 12:59













$() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

– 9769953
Nov 23 '18 at 13:02





$() is a process substitution; in this case, of an empty command, so it doesn't actually do anything.

– 9769953
Nov 23 '18 at 13:02




1




1





From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

– kvantour
Nov 23 '18 at 13:08







From a quick google translate I get: Arguments are parsed by spaces, and flags by slashes. We need to get around both. Spaces are traversed with $IFS$(), and slashes with .... I do believe this is a typo. IFS is the Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read built-in command. The default value is <space><tab><newline>. So I believe the website should have stated Spaces are traversed with $IFS, and slashes ...

– kvantour
Nov 23 '18 at 13:08














1 Answer
1






active

oldest

votes


















5














By $IFS$() they probably mean they change IFS from default white space, to end of string.



From bash manpages:




IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''.




They mean they do IFS=$() which acts the same as doing IFS=$'', declaring that field separator is null character, which marks end of a string.



$() means return the output of command inside parenthesizes, which the is the same as you just pressing Enter key in terminal.



Example:



$ cat test
1 2 3 4 5 6 7
8 9


It will take every number as new variable, because every whitespace (be it single space, tab or new line is considered field separator)



$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


If we change IFS to $(), output is the same as is in the file:



$ IFS=$();for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


Unset IFS and it goes back to looking whitespace as IFS



$ unset IFS
$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


you can similarly make IFS change to null character with $''



$ IFS=$'';for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


IFS=$() is basically the same as IFS= or IFS="", you are declaring it equal to empty string so bash looks for end of strings as separators.






share|improve this answer





















  • 3





    For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

    – Socowi
    Nov 23 '18 at 13:36








  • 2





    Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

    – Socowi
    Nov 23 '18 at 14:13













  • You're really good, buddy

    – anonymous
    Nov 23 '18 at 15:59


















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









5














By $IFS$() they probably mean they change IFS from default white space, to end of string.



From bash manpages:




IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''.




They mean they do IFS=$() which acts the same as doing IFS=$'', declaring that field separator is null character, which marks end of a string.



$() means return the output of command inside parenthesizes, which the is the same as you just pressing Enter key in terminal.



Example:



$ cat test
1 2 3 4 5 6 7
8 9


It will take every number as new variable, because every whitespace (be it single space, tab or new line is considered field separator)



$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


If we change IFS to $(), output is the same as is in the file:



$ IFS=$();for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


Unset IFS and it goes back to looking whitespace as IFS



$ unset IFS
$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


you can similarly make IFS change to null character with $''



$ IFS=$'';for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


IFS=$() is basically the same as IFS= or IFS="", you are declaring it equal to empty string so bash looks for end of strings as separators.






share|improve this answer





















  • 3





    For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

    – Socowi
    Nov 23 '18 at 13:36








  • 2





    Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

    – Socowi
    Nov 23 '18 at 14:13













  • You're really good, buddy

    – anonymous
    Nov 23 '18 at 15:59
















5














By $IFS$() they probably mean they change IFS from default white space, to end of string.



From bash manpages:




IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''.




They mean they do IFS=$() which acts the same as doing IFS=$'', declaring that field separator is null character, which marks end of a string.



$() means return the output of command inside parenthesizes, which the is the same as you just pressing Enter key in terminal.



Example:



$ cat test
1 2 3 4 5 6 7
8 9


It will take every number as new variable, because every whitespace (be it single space, tab or new line is considered field separator)



$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


If we change IFS to $(), output is the same as is in the file:



$ IFS=$();for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


Unset IFS and it goes back to looking whitespace as IFS



$ unset IFS
$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


you can similarly make IFS change to null character with $''



$ IFS=$'';for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


IFS=$() is basically the same as IFS= or IFS="", you are declaring it equal to empty string so bash looks for end of strings as separators.






share|improve this answer





















  • 3





    For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

    – Socowi
    Nov 23 '18 at 13:36








  • 2





    Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

    – Socowi
    Nov 23 '18 at 14:13













  • You're really good, buddy

    – anonymous
    Nov 23 '18 at 15:59














5












5








5







By $IFS$() they probably mean they change IFS from default white space, to end of string.



From bash manpages:




IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''.




They mean they do IFS=$() which acts the same as doing IFS=$'', declaring that field separator is null character, which marks end of a string.



$() means return the output of command inside parenthesizes, which the is the same as you just pressing Enter key in terminal.



Example:



$ cat test
1 2 3 4 5 6 7
8 9


It will take every number as new variable, because every whitespace (be it single space, tab or new line is considered field separator)



$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


If we change IFS to $(), output is the same as is in the file:



$ IFS=$();for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


Unset IFS and it goes back to looking whitespace as IFS



$ unset IFS
$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


you can similarly make IFS change to null character with $''



$ IFS=$'';for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


IFS=$() is basically the same as IFS= or IFS="", you are declaring it equal to empty string so bash looks for end of strings as separators.






share|improve this answer















By $IFS$() they probably mean they change IFS from default white space, to end of string.



From bash manpages:




IFS The Internal Field Separator that is used for word splitting after expansion and to split lines into words with the read builtin command. The default value is ``<space><tab><newline>''.




They mean they do IFS=$() which acts the same as doing IFS=$'', declaring that field separator is null character, which marks end of a string.



$() means return the output of command inside parenthesizes, which the is the same as you just pressing Enter key in terminal.



Example:



$ cat test
1 2 3 4 5 6 7
8 9


It will take every number as new variable, because every whitespace (be it single space, tab or new line is considered field separator)



$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


If we change IFS to $(), output is the same as is in the file:



$ IFS=$();for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


Unset IFS and it goes back to looking whitespace as IFS



$ unset IFS
$ for i in $(cat test); do echo $i; done
1
2
3
4
5
6
7
8
9


you can similarly make IFS change to null character with $''



$ IFS=$'';for i in $(cat test); do echo $i; done
1 2 3 4 5 6 7
8 9


IFS=$() is basically the same as IFS= or IFS="", you are declaring it equal to empty string so bash looks for end of strings as separators.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 23 '18 at 14:22

























answered Nov 23 '18 at 13:11









rAlenrAlen

31318




31318








  • 3





    For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

    – Socowi
    Nov 23 '18 at 13:36








  • 2





    Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

    – Socowi
    Nov 23 '18 at 14:13













  • You're really good, buddy

    – anonymous
    Nov 23 '18 at 15:59














  • 3





    For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

    – Socowi
    Nov 23 '18 at 13:36








  • 2





    Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

    – Socowi
    Nov 23 '18 at 14:13













  • You're really good, buddy

    – anonymous
    Nov 23 '18 at 15:59








3




3





For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

– Socowi
Nov 23 '18 at 13:36







For me $() doesn't produce a newline. x=$(); printf %q "$x" prints '' (empty string) but x=$(); printf %q "$x" prints $'n' (newline). In your example IFS=$(); for ... the output is the same as in the file, because the whole file is read in one iteration. IFS=$() is the same as IFS="" or IFS=.

– Socowi
Nov 23 '18 at 13:36






2




2





Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

– Socowi
Nov 23 '18 at 14:13







Better, but still bit misleading. It is true that strings are terminated by a null character, but in bash you can never access that null character. It is processed internally. Writing $'' would actually produce a string with two null characters, the one you wrote down explicitly and the one bash appends automatically to mark the end of the string. However, since bash terminates strings at the first null character, there is no difference between $'', "" or even $' some long string'.

– Socowi
Nov 23 '18 at 14:13















You're really good, buddy

– anonymous
Nov 23 '18 at 15:59





You're really good, buddy

– anonymous
Nov 23 '18 at 15:59





這個網誌中的熱門文章

Xamarin.form Move up view when keyboard appear

Post-Redirect-Get with Spring WebFlux and Thymeleaf

Anylogic : not able to use stopDelay()