mirror of
https://github.com/koalaman/shellcheck.git
synced 2025-10-03 19:29:44 +08:00
Updated SC2149 (markdown)
10
SC2149.md
10
SC2149.md
@@ -4,7 +4,7 @@ _Note: Removed in [v0.5.0 - 2018-06-01](https://github.com/koalaman/shellcheck/c
|
||||
|
||||
### Problematic code:
|
||||
|
||||
```sh
|
||||
```bash
|
||||
# Regular array
|
||||
index=42
|
||||
echo $((array[$index]))
|
||||
@@ -12,7 +12,7 @@ echo $((array[$index]))
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```bash
|
||||
# Associative array
|
||||
index=banana
|
||||
echo $((array[$index]))
|
||||
@@ -20,7 +20,7 @@ echo $((array[$index]))
|
||||
|
||||
### Correct code:
|
||||
|
||||
```
|
||||
```bash
|
||||
# Regular array
|
||||
index=42
|
||||
echo $((array[index]))
|
||||
@@ -28,7 +28,7 @@ echo $((array[index]))
|
||||
|
||||
or
|
||||
|
||||
```sh
|
||||
```bash
|
||||
# Associative array
|
||||
index=banana
|
||||
echo $((array[\$index]))
|
||||
@@ -40,7 +40,7 @@ For a numerically indexed array, the `$` is mostly pointless and can be removed
|
||||
|
||||
For associative arrays, the `$` should be escaped to avoid accidental dereferencing:
|
||||
|
||||
```sh
|
||||
```bash
|
||||
declare -A array
|
||||
index='$1'
|
||||
array[$index]=42
|
||||
|
Reference in New Issue
Block a user