What is the Maximum number of characters that i can store in a variable?

Hi,

Can any one tell me, what is the maximum number of characters that can be stored in a variable?

Thanks in Advance,

Shan

Which language?

Which OS?

Which architecture?

Language : Unix (shell script)
OS : UNIX System V Release 4.0 Version 3.0

By character you mean ASCII character?

8 bits or byte can hold 256 possible values (2^8=256)

C char is 1 byte
C undigned char 1 byte
so then...
C short int 2 bytes
C unsigned short int 2 bytes
C (long) int 4 bytes
C float 4 bytes
C double 8 bytes
In Java byte

By character you mean UCS-2?
16 bits
C short int
C int (sometimes)
Java char and Java short int

By character you mean UCS-4
32 bits
C int (usual)
C long int
Java int

64 bits longword or quadword
C long int (on 64 bit machine)
Java long int

Sometimes it depends on your machine

To allocate space to hold 14 int's

int *ip = malloc(14 * sizeof(int));

whould make room for 14 integers depending on your machine.

I know that some commands on some flavours of Unix running on certain architectures may have restrictions (1024 or 2048 chars), but these are imposed by certain commands such as grep and others under those OSes. Most modern *nix shells are fairly flexible, and you can write to arrays, use xargs, and perform other chicanery to get around any limits you encounter. The Korn shell has a limit of 1024 array elements. I'm not aware of any other limits.

Why would you want to store a huge amount of data in a shell variable anyway??

Cheers
ZB

Thanks for all your valuable suggestions.

I store a list of mail ids in a .lis file and from a shell script i retrieve all the mail ids and put it in a variable by using blankspace as delimiter.

And i export that variable. So, there is another program which makes use of that exported variable to send the e-mail to e-mail addresses stored in that variable.

When i tried with multiple entires, it allows only 512 characters.

Please suggest me if there is any work around.

Thanks and Regards

Shanmugam

How many addresses, if it is less then 1024 you can use a variable array in the Korn shell. You could also have unlimited length on a variable if you use PERL, which is loaded on most unix boxes.

If you are using sendmail, then you can create a mail alias which includes this file. See man aliases for details.

Thanks Ygor, but am using mailx command.

Let me try to modify the program with your help....

beilstwh, thanks to you too...

but the mail ids may grow larger and larger... so i can not predict the number of characters...

Anyhow, i will try to use the work around suggested by you (perl).

Regards,

Shan

I could be mistaken here, but this sounds like you're after the kernel ARG_MAX value.

From /etc/conf/cf.d/mtune:

  • General Kernel Parameters ------------------
    ARG_MAX 5120 1024 51200

Our /etc/conf/cf.d/stune has:

ARG_MAX 51200

Set your stune value and, as root, do an idbuild then reboot.

You'll have your [much] larger capacity