help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Allowing dash in variable and function names


From: Eli Schwartz
Subject: Re: Allowing dash in variable and function names
Date: Tue, 6 Apr 2021 01:01:30 -0400

On 4/5/21 9:53 PM, pauline-galea@gmx.com wrote:
> 
> Could gnu bash start allowing "-" in variable and function names
> as with lisp?
> 
> Regards

GNU bash already supports this as a bash extension for function names,
unless bash is in posix mode.

Variables are, however, indeed forbidden to contain a dash either way.
And it will never be added, because it would break backward
compatibility. Previously existing code of the form

var="string"
echo "$var-suffix"

would formerly print "string-suffix", but switch to printing "" because
the dash and the contents following it would suddenly be parsed as a
variable reference.

echo ${var-suffix} would not work either, even though ${} is the usual
approach to disambiguating variable names, because that too has a
pre-existing meaning:

    When not performing substring expansion, using the forms documented
    below (e.g., :-), bash tests for a parameter that is unset or null.
    Omitting the colon results in a test only for a parameter that is
    unset.

    ${parameter:-word}
        Use Default Values. If parameter is unset or null, the expansion
        of word is substituted. Otherwise, the value of parameter is
        substituted.


-- 
Eli Schwartz
Arch Linux Bug Wrangler and Trusted User

Attachment: OpenPGP_signature
Description: OpenPGP digital signature


reply via email to

[Prev in Thread] Current Thread [Next in Thread]