Reputation: 4803
I have the following ksh script to run:
temp=`<some_command>`
eval set -A array $temp
The variable temp
contains the output from the command, with output as space separated strings.
But on some occasions, I would come across the following error:
array: 0403-046 The specified subscript cannot be greater than 4095.
In this case, is there a way to set the array to the first 4096 space-separated strings in temp
?
Another alternative is to limit the output from <some_command>
(output to stdout) to no more than 4096 lines (one string each line). Could this be done with ksh?
Upvotes: 0
Views: 2598
Reputation: 8446
You can of course use a newer version of ksh93 - with a larger limit on array sizes. If that is not an option, try the following:
# some_command <n> produces <n> lines of text:
$ function some_command {
echo a{1..$1} | tr ' ' $'\n'
}
$ some_command 5
a1
a2
a3
a4
a5
This is your answer:
$ set -A array $(
some_command 4100 | head -4096
)
$ echo ${#array[@]}
4096
Upvotes: 2