Does readarray allow to specify line delimiter?











up vote
1
down vote

favorite












In bash read builtin has -d for us to specify line delimiter other than newline



Does readarray provide some way to specify line delimiter?




  • Is it correct that it has no an option for that purpose?

  • Is there a shell default variable for that purpose, similar to IFS for field delimiter?


Thanks.





After I saw steeldriver's comment,



$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ help readarray
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from a file into an array variable.

A synonym for `mapfile'.


but later I discovered:



$ help mapfile
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into an indexed array variable.

Read lines from the standard input into the indexed array variable ARRAY, or
from file descriptor FD if the -u option is supplied. The variable MAPFILE
is the default ARRAY.

Options:
-d delim Use DELIM to terminate lines, instead of newline
...









share|improve this question




















  • 1




    It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
    – steeldriver
    2 days ago










  • Thanks. Updated.
    – Tim
    2 days ago






  • 1




    @JeffSchaller "What happened when you tried?"
    – Tim
    2 days ago

















up vote
1
down vote

favorite












In bash read builtin has -d for us to specify line delimiter other than newline



Does readarray provide some way to specify line delimiter?




  • Is it correct that it has no an option for that purpose?

  • Is there a shell default variable for that purpose, similar to IFS for field delimiter?


Thanks.





After I saw steeldriver's comment,



$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ help readarray
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from a file into an array variable.

A synonym for `mapfile'.


but later I discovered:



$ help mapfile
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into an indexed array variable.

Read lines from the standard input into the indexed array variable ARRAY, or
from file descriptor FD if the -u option is supplied. The variable MAPFILE
is the default ARRAY.

Options:
-d delim Use DELIM to terminate lines, instead of newline
...









share|improve this question




















  • 1




    It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
    – steeldriver
    2 days ago










  • Thanks. Updated.
    – Tim
    2 days ago






  • 1




    @JeffSchaller "What happened when you tried?"
    – Tim
    2 days ago















up vote
1
down vote

favorite









up vote
1
down vote

favorite











In bash read builtin has -d for us to specify line delimiter other than newline



Does readarray provide some way to specify line delimiter?




  • Is it correct that it has no an option for that purpose?

  • Is there a shell default variable for that purpose, similar to IFS for field delimiter?


Thanks.





After I saw steeldriver's comment,



$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ help readarray
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from a file into an array variable.

A synonym for `mapfile'.


but later I discovered:



$ help mapfile
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into an indexed array variable.

Read lines from the standard input into the indexed array variable ARRAY, or
from file descriptor FD if the -u option is supplied. The variable MAPFILE
is the default ARRAY.

Options:
-d delim Use DELIM to terminate lines, instead of newline
...









share|improve this question















In bash read builtin has -d for us to specify line delimiter other than newline



Does readarray provide some way to specify line delimiter?




  • Is it correct that it has no an option for that purpose?

  • Is there a shell default variable for that purpose, similar to IFS for field delimiter?


Thanks.





After I saw steeldriver's comment,



$ bash --version
GNU bash, version 4.4.19(1)-release (x86_64-pc-linux-gnu)
Copyright (C) 2016 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>

This is free software; you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

$ help readarray
readarray: readarray [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from a file into an array variable.

A synonym for `mapfile'.


but later I discovered:



$ help mapfile
mapfile: mapfile [-d delim] [-n count] [-O origin] [-s count] [-t] [-u fd] [-C callback] [-c quantum] [array]
Read lines from the standard input into an indexed array variable.

Read lines from the standard input into the indexed array variable ARRAY, or
from file descriptor FD if the -u option is supplied. The variable MAPFILE
is the default ARRAY.

Options:
-d delim Use DELIM to terminate lines, instead of newline
...






bash array






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 days ago

























asked 2 days ago









Tim

1




1








  • 1




    It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
    – steeldriver
    2 days ago










  • Thanks. Updated.
    – Tim
    2 days ago






  • 1




    @JeffSchaller "What happened when you tried?"
    – Tim
    2 days ago
















  • 1




    It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
    – steeldriver
    2 days ago










  • Thanks. Updated.
    – Tim
    2 days ago






  • 1




    @JeffSchaller "What happened when you tried?"
    – Tim
    2 days ago










1




1




It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
– steeldriver
2 days ago




It depends how recent a version of bash (it was introduced in 4.4 IIRC) - a simple perusal of the manpage should indicate whether yours does (-d delim)
– steeldriver
2 days ago












Thanks. Updated.
– Tim
2 days ago




Thanks. Updated.
– Tim
2 days ago




1




1




@JeffSchaller "What happened when you tried?"
– Tim
2 days ago






@JeffSchaller "What happened when you tried?"
– Tim
2 days ago












1 Answer
1






active

oldest

votes

















up vote
3
down vote



accepted










Since bash version 4.4, yes it does. From the release announcement Bash-4.4 Release Available:




The most notable new features are mapfile's ability to use an arbitrary
record delimiter;




(readarray being a synonym for mapfile). The description in man bash is



          -d     The first character of delim is used  to  terminate  each
input line, rather than newline.





share|improve this answer





















  • Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
    – Tim
    2 days ago












  • @Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
    – steeldriver
    2 days ago










  • In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
    – Tim
    2 days ago








  • 1




    @Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
    – Kusalananda
    2 days ago






  • 2




    @Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
    – Kusalananda
    2 days ago













Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "106"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482358%2fdoes-readarray-allow-to-specify-line-delimiter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
3
down vote



accepted










Since bash version 4.4, yes it does. From the release announcement Bash-4.4 Release Available:




The most notable new features are mapfile's ability to use an arbitrary
record delimiter;




(readarray being a synonym for mapfile). The description in man bash is



          -d     The first character of delim is used  to  terminate  each
input line, rather than newline.





share|improve this answer





















  • Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
    – Tim
    2 days ago












  • @Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
    – steeldriver
    2 days ago










  • In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
    – Tim
    2 days ago








  • 1




    @Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
    – Kusalananda
    2 days ago






  • 2




    @Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
    – Kusalananda
    2 days ago

















up vote
3
down vote



accepted










Since bash version 4.4, yes it does. From the release announcement Bash-4.4 Release Available:




The most notable new features are mapfile's ability to use an arbitrary
record delimiter;




(readarray being a synonym for mapfile). The description in man bash is



          -d     The first character of delim is used  to  terminate  each
input line, rather than newline.





share|improve this answer





















  • Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
    – Tim
    2 days ago












  • @Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
    – steeldriver
    2 days ago










  • In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
    – Tim
    2 days ago








  • 1




    @Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
    – Kusalananda
    2 days ago






  • 2




    @Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
    – Kusalananda
    2 days ago















up vote
3
down vote



accepted







up vote
3
down vote



accepted






Since bash version 4.4, yes it does. From the release announcement Bash-4.4 Release Available:




The most notable new features are mapfile's ability to use an arbitrary
record delimiter;




(readarray being a synonym for mapfile). The description in man bash is



          -d     The first character of delim is used  to  terminate  each
input line, rather than newline.





share|improve this answer












Since bash version 4.4, yes it does. From the release announcement Bash-4.4 Release Available:




The most notable new features are mapfile's ability to use an arbitrary
record delimiter;




(readarray being a synonym for mapfile). The description in man bash is



          -d     The first character of delim is used  to  terminate  each
input line, rather than newline.






share|improve this answer












share|improve this answer



share|improve this answer










answered 2 days ago









steeldriver

33.6k34982




33.6k34982












  • Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
    – Tim
    2 days ago












  • @Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
    – steeldriver
    2 days ago










  • In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
    – Tim
    2 days ago








  • 1




    @Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
    – Kusalananda
    2 days ago






  • 2




    @Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
    – Kusalananda
    2 days ago




















  • Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
    – Tim
    2 days ago












  • @Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
    – steeldriver
    2 days ago










  • In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
    – Tim
    2 days ago








  • 1




    @Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
    – Kusalananda
    2 days ago






  • 2




    @Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
    – Kusalananda
    2 days ago


















Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
– Tim
2 days ago






Thanks. Does delimiter mean the same as a separator and thus is to be removed? I have a file whose content is 1 2 3. and readarray -d "2" myarr < f1 and echo "${myarr[0]}" outputs 1 2 and echo "${myarr[1]}" outputs 3.
– Tim
2 days ago














@Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
– steeldriver
2 days ago




@Tim you can add -t if you want to "Remove a trailing DELIM" - exactly as you would for the default (newline) delimiter
– steeldriver
2 days ago












In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
– Tim
2 days ago






In 1 2 3, 2 isn't trailing however. What does "trailing" mean?
– Tim
2 days ago






1




1




@Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
– Kusalananda
2 days ago




@Tim To remove the trailing delimiter means to remove the delimiter from each element of the array. In your case, that would result in the two elements 1 and 3 (the 1 would have a space after it and the 3 would be preceded by a space and probably followed by a newline).
– Kusalananda
2 days ago




2




2




@Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
– Kusalananda
2 days ago






@Tim There is no mentioning of "separator". The delimiter (newline, or the character specified with -d) is included in the data unless -t is also used. See also When to use the terms "delimiter," "terminator," and "separator"
– Kusalananda
2 days ago




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f482358%2fdoes-readarray-allow-to-specify-line-delimiter%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

If I really need a card on my start hand, how many mulligans make sense? [duplicate]

Alcedinidae

Can an atomic nucleus contain both particles and antiparticles? [duplicate]