notes: add an interesting case of shell variables vs environment variables

This commit is contained in:
Khaïs COLIN 2025-02-10 17:30:12 +01:00
parent f3c875c34e
commit 9c81ac832a
Signed by: logistic-bot
SSH key fingerprint: SHA256:RlpiqKeXpcPFZZ4y9Ou4xi2M8OhRJovIwDlbCaMsuAo

View file

@ -213,6 +213,17 @@ The form is $VAR, where VAR may only contain the following characters:
* _
* 0-9 (not in the first character)
Just noticed an interesting case:
```shell
bash-5.2$ VAR=hello # we set a shell variable (NOT environment variable)
bash-5.2$ VAR=hi env | grep VAR=; env | grep VAR= # here VAR is an environment variable, which is only valid for the next command (the second env returns nothing, confirming that it is not valid for that command)
VAR=hi
bash-5.2$ env | grep VAR= # var is not an environment variable
bash-5.2$ echo $VAR # but it is a shell variable
hello
```
Luckily for us, we don't have to handle shell variables, nor do we have to handle `VAR=value` or `VAR=value cmd`.
#### Word Splitting
cf. 3.5.7 Word Splitting