Discussion:
[Help-bash] Variable name allowed characters.
Mike Mestnik
2017-07-24 17:55:59 UTC
Permalink
Hello,
I'm working on a parser for bash and I was unable to find an
authoritative reference on the format of variable names. One
[1]reference I found said only letters and underscore, but I'm certain
much more is allowed. Several other references I looked at were about
as much help. I'm looking for a regex, as I'm [2]writing in perl, but
any description will do.

1. https://bash.cyberciti.biz/guide/Rules_for_Naming_variable_name
2. https://github.com/cheako/MarpaX-Languages-Bash-AST/blob/ca20998abd231b60441f1decda13ee3bfcf51c64/lib/MarpaX/Languages/Bash/AST.pm#L604
Chet Ramey
2017-07-24 18:17:41 UTC
Permalink
Post by Mike Mestnik
Hello,
I'm working on a parser for bash and I was unable to find an
authoritative reference on the format of variable names.
Variable names are defined as `names' in the man page:

name A word consisting only of alphanumeric characters and under-
scores, and beginning with an alphabetic character or an under-
score. Also referred to as an identifier.

If you want something more standard,

http://pubs.opengroup.org/onlinepubs/9699919799/basedefs/V1_chap03.html#tag_03_235
--
``The lyf so short, the craft so long to lerne.'' - Chaucer
``Ars longa, vita brevis'' - Hippocrates
Chet Ramey, UTech, CWRU ***@case.edu http://cnswww.cns.cwru.edu/~chet/
Loading...