% is a valid variable name all by itself
Interesting... This fact feels vaguely familiar to me somehow, as though I might've known that at one point in time, but I'm not sure I would've remembered or thought of it had you not mentioned it. 🤔
Was this purposely built in or simply a side effect of the way you implemented variables into the language? In any case, I'm noticing that variables named
%
seem to have a few unique quirks to them - namely, that:
- A script can have multiple independent local variables with that name:
//var -s % 0123 , % 4567 , % 89AB , % CDEF | echo -ga $var( % , 0 )
* Set % to 0123
-
* Set % to 4567
-
* Set % to 89AB
-
* Set % to CDEF
-
4
- The
=
assignment operator cannot be used to assign values to nor create them:alias nullvar_test {
% = hello
}
* /%: not connected to server (...)
-
- The optional
=
of the /var
command will be treated as part of the value rather than as part of the command's syntax; mathematical expressions will, of course, not be calculated in such cases://var -s % 2 ^ 3 , % = 2 ^ 3
* Set % to 8
-
* Set % to = 2 ^ 3
-
- Retrieving values stored in them requires explicit use of
$var( % , N ).value
: (Presumably to avoid conflict with the modulus operator in certain contexts?)//var -s % hello | echo -ga % | echo -ga $var( % , 1 ).value
* Set % to hello
-
%
hello
- Commands like
/inc
, /dec
, and /unset
will only modify a global version://var -s % 5 | dec -s % | set -s % 99 | inc -s % | unset -s % | echo -ga $var( % , 1 ).value
* Set % to 5
-
* Dec % to -1
-
* Set % to 99
-
* Inc % to 100
-
* Unset %
-
5
Whether or not any of these are bugs and warrant their own reports, I'm not sure... but, I figured it'd at least be worth mentioning them here so that anyone who happens upon this post and wants to try using null-named variables will be aware of their pitfalls and limitations.
(Tested on both v7.71 and beta v7.71.1275.)