Operating System - HP-UX
1819681 Members
3514 Online
109605 Solutions
New Discussion юеВ

Shell String variable maximum Length

 
SOLVED
Go to solution
Shaji Nair_1
Occasional Advisor

Shell String variable maximum Length

Hi,
I would like to know is there any maximum length for a string variable in POSIX shell. I am not sure howmany characters are my query going to return to the variable.

Thanks in advance.

Regards
Shaji
5 REPLIES 5
harry d brown jr
Honored Contributor
Solution

Re: Shell String variable maximum Length

Excellent reason to switch to perl.

length is 256.

#!/usr/bin/ksh
read linestuff
echo "--------------------------------------------------"
dummy=${#linestuff}
echo length is $dummy
echo "--------------------------------------------------"
echo $linestuff


live free or die
harry
Live Free or Die
john korterman
Honored Contributor

Re: Shell String variable maximum Length

Hi,
I can only achieve 255, and that is including variable name and equal sign - but one does not make a big difference to me.

regards,
John K.
it would be nice if you always got a second chance
Fragon
Trusted Contributor

Re: Shell String variable maximum Length

For C shell, it's up to 1024!

-ux
curt larson_1
Honored Contributor

Re: Shell String variable maximum Length

if your wondering about the length of the variable name, ie thisreallylongvariablename is 26 characters in length and as previously pointed out has a practial limit that is a bit less then 256 characters.

if your wondering about the string lenght of a a variable, ie a="abcdef", the string length of a (${#a}) is 6 characters.

my testing with
read var
the shell on my old desktop system running 11.0 runs into memory problems when the file/string is >5M
Shaji Nair_1
Occasional Advisor

Re: Shell String variable maximum Length

Yes, perl is one option and i am going to port the script in perl. I am porting a old shell script to work with a new product and i was wondering why the old script is creating lots of temporary files when i can take everything onto a variable (I was thinking in perl). Now i know why they are creating lots of temporary files to capture the output of the command. Thanks for all you help. I have decided to keep it as it is and will port it to perl.

Regards
Shaji