KSH/BASH Maximum size of an Array
Clash Royale CLAN TAG#URR8PPP
up vote
4
down vote
favorite
What is the maximum size of array for ksh and bash scripting?
Example: Suppose I have an array of 10 elements. What will be the maximum number of string count that a particular index of an array can hold? What will be the maximum size of an array for the same?
I am new to Unix. I imagine this is a common question but I didn't manage to find an answer so I decided to ask here.
bash shell-script ksh
add a comment |Â
up vote
4
down vote
favorite
What is the maximum size of array for ksh and bash scripting?
Example: Suppose I have an array of 10 elements. What will be the maximum number of string count that a particular index of an array can hold? What will be the maximum size of an array for the same?
I am new to Unix. I imagine this is a common question but I didn't manage to find an answer so I decided to ask here.
bash shell-script ksh
1
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in awhile
loop?
â l0b0
Apr 9 '15 at 10:03
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43
add a comment |Â
up vote
4
down vote
favorite
up vote
4
down vote
favorite
What is the maximum size of array for ksh and bash scripting?
Example: Suppose I have an array of 10 elements. What will be the maximum number of string count that a particular index of an array can hold? What will be the maximum size of an array for the same?
I am new to Unix. I imagine this is a common question but I didn't manage to find an answer so I decided to ask here.
bash shell-script ksh
What is the maximum size of array for ksh and bash scripting?
Example: Suppose I have an array of 10 elements. What will be the maximum number of string count that a particular index of an array can hold? What will be the maximum size of an array for the same?
I am new to Unix. I imagine this is a common question but I didn't manage to find an answer so I decided to ask here.
bash shell-script ksh
bash shell-script ksh
edited Sep 22 '16 at 22:45
wjandrea
462312
462312
asked Apr 9 '15 at 5:54
Aman
1561215
1561215
1
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in awhile
loop?
â l0b0
Apr 9 '15 at 10:03
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43
add a comment |Â
1
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in awhile
loop?
â l0b0
Apr 9 '15 at 10:03
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43
1
1
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in a
while
loop?â l0b0
Apr 9 '15 at 10:03
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in a
while
loop?â l0b0
Apr 9 '15 at 10:03
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43
add a comment |Â
3 Answers
3
active
oldest
votes
up vote
12
down vote
accepted
i=0
while true; do
a[$i]=foo
i=$((i+1))
printf "r%d " $i
done
This simple script shows on my systems (Gnu/Linux and Solaris):
ksh88
limits the size to2^12-1
(4095). (subscript out of range
). Some older releases like the one on HP-UX limit the size to1023
.ksh93
limits the size of a array to2^22-1
(4194303), your mileage may vary.bash
doesn't look to impose any hard-coded limit outside the one dictated by the underlying memory resources available. For example bash uses1.3 GB
of virtual memory for an array size of18074340
.
Note: I gave up with mksh
which was too slow executing the loop (more than one hundred times slower than zsh
, ksh93
and bash
.)
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
 |Â
show 2 more comments
up vote
3
down vote
There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic)) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
http://www.gnu.org/software/bash/manual/html_node/Arrays.html
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
add a comment |Â
up vote
2
down vote
It depends on the implementation. In ksh there are documented "implementation defined limits" for indexed arrays. For ksh88
there are systems existing with a limit of 1023, for ksh93
the minimum limit required by an implementation is 4095. So you cannot count on having more available than that! (If you are only implementing for a specific system you can test your system limits as proposed in another answer here.)
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
add a comment |Â
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
12
down vote
accepted
i=0
while true; do
a[$i]=foo
i=$((i+1))
printf "r%d " $i
done
This simple script shows on my systems (Gnu/Linux and Solaris):
ksh88
limits the size to2^12-1
(4095). (subscript out of range
). Some older releases like the one on HP-UX limit the size to1023
.ksh93
limits the size of a array to2^22-1
(4194303), your mileage may vary.bash
doesn't look to impose any hard-coded limit outside the one dictated by the underlying memory resources available. For example bash uses1.3 GB
of virtual memory for an array size of18074340
.
Note: I gave up with mksh
which was too slow executing the loop (more than one hundred times slower than zsh
, ksh93
and bash
.)
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
 |Â
show 2 more comments
up vote
12
down vote
accepted
i=0
while true; do
a[$i]=foo
i=$((i+1))
printf "r%d " $i
done
This simple script shows on my systems (Gnu/Linux and Solaris):
ksh88
limits the size to2^12-1
(4095). (subscript out of range
). Some older releases like the one on HP-UX limit the size to1023
.ksh93
limits the size of a array to2^22-1
(4194303), your mileage may vary.bash
doesn't look to impose any hard-coded limit outside the one dictated by the underlying memory resources available. For example bash uses1.3 GB
of virtual memory for an array size of18074340
.
Note: I gave up with mksh
which was too slow executing the loop (more than one hundred times slower than zsh
, ksh93
and bash
.)
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
 |Â
show 2 more comments
up vote
12
down vote
accepted
up vote
12
down vote
accepted
i=0
while true; do
a[$i]=foo
i=$((i+1))
printf "r%d " $i
done
This simple script shows on my systems (Gnu/Linux and Solaris):
ksh88
limits the size to2^12-1
(4095). (subscript out of range
). Some older releases like the one on HP-UX limit the size to1023
.ksh93
limits the size of a array to2^22-1
(4194303), your mileage may vary.bash
doesn't look to impose any hard-coded limit outside the one dictated by the underlying memory resources available. For example bash uses1.3 GB
of virtual memory for an array size of18074340
.
Note: I gave up with mksh
which was too slow executing the loop (more than one hundred times slower than zsh
, ksh93
and bash
.)
i=0
while true; do
a[$i]=foo
i=$((i+1))
printf "r%d " $i
done
This simple script shows on my systems (Gnu/Linux and Solaris):
ksh88
limits the size to2^12-1
(4095). (subscript out of range
). Some older releases like the one on HP-UX limit the size to1023
.ksh93
limits the size of a array to2^22-1
(4194303), your mileage may vary.bash
doesn't look to impose any hard-coded limit outside the one dictated by the underlying memory resources available. For example bash uses1.3 GB
of virtual memory for an array size of18074340
.
Note: I gave up with mksh
which was too slow executing the loop (more than one hundred times slower than zsh
, ksh93
and bash
.)
edited Aug 20 at 4:10
ñÃÂsýù÷
15.8k92563
15.8k92563
answered Apr 9 '15 at 7:51
jlliagre
45.2k578125
45.2k578125
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
 |Â
show 2 more comments
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
1
1
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
According to the ksh documentation you cannot count on the values examined here; it depends on the actual implementation on the system. (See my answer.)
â Janis
Apr 9 '15 at 8:07
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@Janis Indeed, thanks. Answer updated to state this is implementation/configuration dependent.
â jlliagre
Apr 9 '15 at 9:06
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
@jlliagre suppose a string "ABCDEFGH" where each character is of 1 bytes then can i assume for ksh 93 and bash 4.2 array maximum capacity is 4194303 characters.
â Aman
Apr 9 '15 at 10:47
1
1
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
As I wrote, there is no hard-coded maximum capacity for bash. In any case, do you really need more than four millions element in a shell script array? Looks like you might be picking the wrong tool for the job.
â jlliagre
Apr 9 '15 at 10:59
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
@jlliagre I got the concept :)
â Aman
Apr 9 '15 at 12:47
 |Â
show 2 more comments
up vote
3
down vote
There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic)) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
http://www.gnu.org/software/bash/manual/html_node/Arrays.html
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
add a comment |Â
up vote
3
down vote
There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic)) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
http://www.gnu.org/software/bash/manual/html_node/Arrays.html
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
add a comment |Â
up vote
3
down vote
up vote
3
down vote
There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic)) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
http://www.gnu.org/software/bash/manual/html_node/Arrays.html
There is no maximum limit on the size of an array, nor any requirement that members be indexed or assigned contiguously. Indexed arrays are referenced using integers (including arithmetic expressions (see Shell Arithmetic)) and are zero-based; associative arrays use arbitrary strings. Unless otherwise noted, indexed array indices must be non-negative integers.
http://www.gnu.org/software/bash/manual/html_node/Arrays.html
answered Apr 9 '15 at 6:26
Jeight
1,8641925
1,8641925
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
add a comment |Â
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
3
3
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
Well actually the maximum size is the total amount of memory PLUS the total amount of swap space which will vary between system configurations.
â mdpc
Apr 9 '15 at 6:59
2
2
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
@mdpc That would be a hardware limitation and not a limitation of Bash/KSH. :)
â Jeight
Apr 9 '15 at 7:02
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
Hmmm....I believe the OP asked for the MAXIMUM size of an array. :)
â mdpc
Apr 9 '15 at 7:05
1
1
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
@Jeight; This may be true for bash but not for ksh.
â Janis
Apr 9 '15 at 8:09
add a comment |Â
up vote
2
down vote
It depends on the implementation. In ksh there are documented "implementation defined limits" for indexed arrays. For ksh88
there are systems existing with a limit of 1023, for ksh93
the minimum limit required by an implementation is 4095. So you cannot count on having more available than that! (If you are only implementing for a specific system you can test your system limits as proposed in another answer here.)
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
add a comment |Â
up vote
2
down vote
It depends on the implementation. In ksh there are documented "implementation defined limits" for indexed arrays. For ksh88
there are systems existing with a limit of 1023, for ksh93
the minimum limit required by an implementation is 4095. So you cannot count on having more available than that! (If you are only implementing for a specific system you can test your system limits as proposed in another answer here.)
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
add a comment |Â
up vote
2
down vote
up vote
2
down vote
It depends on the implementation. In ksh there are documented "implementation defined limits" for indexed arrays. For ksh88
there are systems existing with a limit of 1023, for ksh93
the minimum limit required by an implementation is 4095. So you cannot count on having more available than that! (If you are only implementing for a specific system you can test your system limits as proposed in another answer here.)
It depends on the implementation. In ksh there are documented "implementation defined limits" for indexed arrays. For ksh88
there are systems existing with a limit of 1023, for ksh93
the minimum limit required by an implementation is 4095. So you cannot count on having more available than that! (If you are only implementing for a specific system you can test your system limits as proposed in another answer here.)
answered Apr 9 '15 at 8:05
Janis
9,76511236
9,76511236
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
add a comment |Â
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
what about pdksh or mksh or oksh?
â Stéphane Chazelas
Apr 9 '15 at 8:22
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
@Stephane; I have no documentation inspected for those two variants of the original ksh. If it's not documented with those tools, I think that you should only (if at all!) rely on the original limits, or in case of single system development (as proposed) to check the supported range.
â Janis
Apr 9 '15 at 11:24
add a comment |Â
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f195191%2fksh-bash-maximum-size-of-an-array%23new-answer', 'question_page');
);
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
1
It is scary that you have to ask this question. Are you absolutely sure you can't handle the values in a
while
loop?â l0b0
Apr 9 '15 at 10:03
@l0b0 hmmm but I just ask it for knowledge purpose because I have a firm believe in the answers that I will get from here apart from that I have did prior lot of google but didn't get any satisfactory answer
â Aman
Apr 9 '15 at 10:43