Created
September 11, 2020 23:57
-
-
Save ErnWong/ee6b2aa06b7064dee853e6e2c9872780 to your computer and use it in GitHub Desktop.
Potential bash test -v bug with associative arrays
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
declare -A myarray | |
myarray["'"]="yes" | |
echo ${!myarray[@]} | |
echo ${myarray["'"]} | |
[[ -v myarray["'"] ]] && echo yes || echo no # Expected: "yes" printed. Actual: "no" printed. | |
# Tested on GNU bash version 4.4.20(1)-release |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Looks like
[[ -v myarray["\'"] ]]
works even though it doesn't need escaping. The problem is when the key is obtained from a variable.