[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: Allowing dash in variable and function names
From: |
pauline-galea |
Subject: |
Re: Allowing dash in variable and function names |
Date: |
Tue, 6 Apr 2021 16:52:17 +0200 |
> Sent: Tuesday, April 06, 2021 at 5:01 PM
> From: "Eli Schwartz" <eschwartz@archlinux.org>
> To: help-bash@gnu.org
> Subject: Re: Allowing dash in variable and function names
>
> 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.
For the official Free Gnu Distributions, would there be problems if bash
scripts do not use posixly correct function names?
> 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.
Thank you for the example.
> 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
>
>