@gcb Sorry, something ate all-important quotes the first time around. Here's a correction:

```
% x='(PATH=2)'
% echo $((x+1))
3
% echo $PATH
2
```

(The original `x=(PATH=2)` without quotes doesn't actually perform any eval.)

Does it make sense now? This is indeed quite subtle.

· · Web · 1 · 2 · 3

"..things that can be parsed as variable names are treated as variable names in arithmetic contexts. ..bash does this *recursively* until it gets to an integer, or to something that can't be parsed as either an integer or a variable name."

lists.gnu.org/archive/html/hel

OMG. This is _not_ documented.

@gcb @rain @kingcons

I hope all the shell scripts in the world are sanitizing their inputs.

@gcb @rain @kingcons

@akkartik @gcb @rain @kingcons i always thought that Bash is terrifying, but i didn't realize it's this terrifying…

Sign in to participate in the conversation
Mastodon

Server run by the main developers of the project 🐘 It is not focused on any particular niche interest - everyone is welcome as long as you follow our code of conduct!