fish-shell / fish-shell/fish-shell
Only start of index expansion needs to be quoted for quoted variable expansion
- Dominant language
- Rust
- Stars
- 34.2k
- Forks
- 2.4k
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 13
Description
Running fish version 3.2.2 (installed via Homebrew) on macOS 11.3 in the stock Terminal.app. I tried fish without third-party customisations by executing `sh -c 'env HOME=$(mktemp -d) fish'` and checked whether it affected the behaviour I am reporting (it did not).
---------
_Einen habe ich noch_\*
The following is related to, but distinct from, #7969 and, AFAICS, not covered by an open issue yet (apologies if I missed something in the depths of #2485).
I’ve noticed (while, mumble, Nova syntax extension, mumble; yes I am really, truly, frightfully sorry) that, **for a double quoted variable expansion, index expansion needs not be quoted in its entirety**. If the opening bracket is included in the quotes, that is enough; see the examples below:
```fish
set var (seq 2)
echo "$var[1..2"] # => 1 2
echo "$var[1.."2] # => 1 2
# index range operator cannot be split up …
echo "$var[1"..2] # => 1 2
echo "$var["1..2] # => 1 2
echo "$var"[1..2] # => 1 2[1..2]
```
This seems counterintuitive, as I am not aware of any other pair-delimited expression that keeps its signification across a quote; at odds with fish’s handling of variable expansion otherwise (the `$` operator(s) and identifier characters cannot cross a quote; neither can the indexing follow after a quote in its entirety); and internally inconsistent, as you cannot do it the other way around (i.e. `echo $var[1.."2]"` throws a syntax error about unmatched square brackets).
\* One more thing.
Contributor guide
Assessment
This issue has not been assessed yet.