Discussion:
Maximum length of variable name
RAL
2018-11-15 18:00:46 UTC
Permalink
Hi,

How is defined the maximum number of characters a variable name can have?
Eric Blake
2018-11-15 18:09:46 UTC
Permalink
Post by RAL
Hi,
How is defined the maximum number of characters a variable name can have?
Bash has no hardcoded limit, thus your maximum is dependent on how much
free memory your system has.
--
Eric Blake, Principal Software Engineer
Red Hat, Inc. +1-919-301-3266
Virtualization: qemu.org | libvirt.org
Robert Elz
2018-11-16 01:49:39 UTC
Permalink
Date: Thu, 15 Nov 2018 12:09:46 -0600
From: Eric Blake <***@redhat.com>
Message-ID: <8491692f-8d4a-f24f-2744-***@redhat.com>

| On 11/15/18 12:00 PM, RAL wrote:
| > How is defined the maximum number of characters a variable name can have?
|
| Bash has no hardcoded limit, thus your maximum is dependent on how much
| free memory your system has.

I maintain the NetBSD sh (an ash derivative) - as part of that I have
a test that (amongst other things) tests long var names - it tests up to
about 1000 chars (including adding one extra char (or deleting the
last) and verifying that different vars result) - I have run that test
against bash with no problems at all.

I can't see any reason that much longer names would not work - given
that you understand that anything using them is not likely to run all
that fast (and will consume more memory than you'd expect probably).

kre

Loading...