Closed multitudes closed 3 months ago
some more cases:
echo "fjskdl$HOMEfjkslda"
export var=$HOME~$HOME
echo $var /$var2~
echo $var $var2/~
echo $var $var2
decide what to do with expansion of Special Parameters, such as $$, $N, $-, ... (https://www.gnu.org/software/bash/manual/bash.html#Special-Parameters). We could completely discard them or print them literally or put out a message, that they are not implemented.
also:
export rr=HOME
export $"$rr"=newHOME
would assign newHOME to variable HOME, presumably because the first "$" gets stripped away / replaced with empty string, and double quotes replaced by expanded $rr variable
export HOME = VAR2
bash: export: `=': not a valid identifier
another interesting case:
echo VAR=~:~
returns VAR=HOMEVAL:HOMEVAL in bash
echo ~:~
returns HOMEVAL:~ in bash
some more cases: echo "fjskdl$HOMEfjkslda"
fjskdl
as output is maybe because the value of $HOME
contains a /
character, which is interpreted as a directory separator. The shell is trying to find a file or directory named fjkslda
in a directory named fjskdl$HOME
. If it doesn't exist, nothing is printed after fjskdl
.
export var=$HOME~$HOME echo $var /$var2~ echo $var $var2/~ echo $var $var2
also
export var=~
lbrusa@c4c1c1:~$ echo $var /$var2~
/home/lbrusa /~
export var=~$HOME
lbrusa@c4c1c1:~$ echo $var /$var2~
~/home/lbrusa /~
lbrusa@c4c1c1:~$ export var=~:$HOME
lbrusa@c4c1c1:~$ echo $var /$var2~
/home/lbrusa:/home/lbrusa /~
It seems ~ get expanded only when alone. if followed by a slash alone it expands but I think I recognize that token? ~/
If followed by$HOME it gets not expanded and merge with ~/home/...
lbrusa@c4c1c1:~$ export var=~
lbrusa@c4c1c1:~$ export var=~$var
lbrusa@c4c1c1:~$ echo $var
~/home/lbrusa
lbrusa@c4c1c1:~$ export var=~$var
lbrusa@c4c1c1:~$ echo $var
~~/home/lbrusa
As for the aboe it makes little sense. WE dont need to replicate the bugs. In the end it is our shell!
another interesting case:
echo VAR=~:~
returns VAR=HOMEVAL:HOMEVAL in bashecho ~:~
returns HOMEVAL:~ in bash
this makes sense though. We should aim for the resolution of vars divided by :
lbrusa@c4c1c1:~$ export var=~:~
lbrusa@c4c1c1:~$ echo $var
/home/lbrusa:/home/lbrusa
lbrusa@c4c1c1:~$
export HOME = VAR2
no spaces between var and value accepted...
export HOME = VAR2
no spaces between var and value accepted...
Yes, but we still need to ensure, that '=' is properly handled and not, i.e. misinterpreted as variable assignment
another interesting case:
echo VAR=~:~
returns VAR=HOMEVAL:HOMEVAL in bashecho ~:~
returns HOMEVAL:~ in bashthis makes sense though. We should aim for the resolution of vars divided by
:
lbrusa@c4c1c1:~$ export var=~:~ lbrusa@c4c1c1:~$ echo $var /home/lbrusa:/home/lbrusa lbrusa@c4c1c1:~$
yes, of course. I put it here to ensure we do not forget.
This were all extras s owe will open a new issue and test for the next version
variables names have a stricter rules.
They matches like in C the regex pattern
[_a-zA-Z][[_0-9a-zA-Z]]*
ex
export [_a-zA-Z][[_0-9a-zA-Z]]*=....
so the var name should match the pattern[_a-zA-Z][[_0-9a-zA-Z]]*
which means, start with letter or underscore and continue with same but allowing digitsalso mentioned in the book https://craftinginterpreters.com/scanning.html chapter 4.3
so this is not possible:
and this is a special case. The expansion mostly happens before the parsing in the tree. var becomes HOME then wehen we unset $var because $var was previously expanded we get
unset HOME
when I doexport $var=home/rpriess
it is reallyexport HOME=home/rpriess