|
Home > Archive > Unix Shell > February 2006 > Max chars in a variable?
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
Max chars in a variable?
|
|
| kk_oop@yahoo.com 2006-02-20, 5:54 pm |
| Hi. I wanted to capture the output of the find command into a script
variable. I am able to do this, but I notice that at some point, if
there are too many files found, I get a script error that says there
are too many characters in my variable.
Does anyone know the max number of chars for a variable? Does it vary
for different shell types? I am currently writing a C-Shell script.
Thanks for any info!
Ken
| |
| Janis Papanagnou 2006-02-20, 5:54 pm |
| kk_oop@yahoo.com wrote:
> Hi. I wanted to capture the output of the find command into a script
> variable. I am able to do this, but I notice that at some point, if
> there are too many files found, I get a script error that says there
> are too many characters in my variable.
>
> Does anyone know the max number of chars for a variable? Does it vary
> for different shell types? I am currently writing a C-Shell script.
>
> Thanks for any info!
>
> Ken
>
Yes, that depends on the shell.
With the current ksh93 I have constructed a string of size 10,000,000.
But I don't know where the limit is (if any other than memory).
Janis
| |
| Chris F.A. Johnson 2006-02-20, 5:54 pm |
| On 2006-02-20, kk_oop@yahoo.com wrote:
> Hi. I wanted to capture the output of the find command into a script
> variable. I am able to do this, but I notice that at some point, if
> there are too many files found, I get a script error that says there
> are too many characters in my variable.
With a Bourne-type shell you are more likely to get a message like:
"Too many arguments", rather than "too many characters".
> Does anyone know the max number of chars for a variable?
I've had millions of characters in a variable in bash as well as a
Bourne shell.
> Does it vary for different shell types?
Quite likely.
> I am currently writing a C-Shell script.
C-shell is not recommended for scripting. See:
<http://www.grymoire.com/Unix/CshTop10.txt>
<http://www.grymoire.com/Unix/Csh.html#uh-0>
<http://www.faqs.org/faqs/unix-faq/shell/csh-whynot/>
--
Chris F.A. Johnson, author | <http://cfaj.freeshell.org>
Shell Scripting Recipes: | My code in this post, if any,
A Problem-Solution Approach | is released under the
2005, Apress | GNU General Public Licence
| |
| kk_oop@yahoo.com 2006-02-20, 8:49 pm |
| Chris F.A. Johnson wrote:
> On 2006-02-20, kk_oop@yahoo.com wrote:
>
> With a Bourne-type shell you are more likely to get a message like:
> "Too many arguments", rather than "too many characters".
Now that you mention it, the actual error was "Too long between ' ' ".
So now I'm thinking perhaps the problem was too many parameters. I
actually took the output of the find command and used it to create a
"cp" command. The idea is that it would copy all the files found by
find into another directory.
Is there an upper limit to the number of parameters allowed? Does that
vary from shell to shell?
Note that I've been told to script using C-Shell, because that what
folks know on the project. However, after checking out these URLs, I'm
going to see if we can start switching over to Bourne.
Thanks,
Ken
| |
| pat foley 2006-02-20, 8:49 pm |
| On 2006-02-21, kk_oop@yahoo.com <kk_oop@yahoo.com> wrote:
> Chris F.A. Johnson wrote:
>
> Now that you mention it, the actual error was "Too long between ' ' ".
> So now I'm thinking perhaps the problem was too many parameters. I
> actually took the output of the find command and used it to create a
> "cp" command. The idea is that it would copy all the files found by
> find into another directory.
>
> Is there an upper limit to the number of parameters allowed? Does that
> vary from shell to shell?
>
> Note that I've been told to script using C-Shell, because that what
> folks know on the project. However, after checking out these URLs, I'm
> going to see if we can start switching over to Bourne.
Are you familiar with xargs?
It may be the simplest solution to your problem.
| |
| Janis Papanagnou 2006-02-20, 8:49 pm |
| kk_oop@yahoo.com wrote:
> Chris F.A. Johnson wrote:
>
>
>
> Now that you mention it, the actual error was "Too long between ' ' ".
> So now I'm thinking perhaps the problem was too many parameters. I
> actually took the output of the find command and used it to create a
> "cp" command. The idea is that it would copy all the files found by
> find into another directory.
>
> Is there an upper limit to the number of parameters allowed? Does that
> vary from shell to shell?
It's a limit on the _buffer size_ that is required for the expanded
arguments when calling an external program. It's primarily a system
not a shell limitation.
> Note that I've been told to script using C-Shell, because that what
> folks know on the project. However, after checking out these URLs, I'm
> going to see if we can start switching over to Bourne.
That's very much to recommend.
Janis
> Thanks,
>
> Ken
>
| |
| Sven Mascheck 2006-02-21, 7:49 am |
| Janis Papanagnou wrote:
> kk_oop@yahoo.com wrote:
[vbcol=seagreen]
The latter is a hard coded *csh limitation about the length
of a single variable. The former ist a kernel limit about
the size of the whole environment. To learn this,
many systems know
$ getconf ARG_MAX
Exceeding this limit only results in an error for one of the
members of the exec(2) family; they return E2BIG (or similar)
then. putenv(3) for example is not affected. And if you stay
with shell built-ins you don't get this error at all.
Upon exec(), shells print the error themselves or call perror(3).
I've only seen "... [Aa]rg(ument) list too long" until now.
[vbcol=seagreen]
>
> It's primarily a system not a shell limitation.
and i've never seen any bourne(-like) shell with any limit like that.
|
|
|
|
|