[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Help-bash] Is it possible to not require escaping to access hash key in
From: |
Peng Yu |
Subject: |
[Help-bash] Is it possible to not require escaping to access hash key in [[ -v ]]? |
Date: |
Wed, 12 Dec 2018 23:27:58 -0600 |
Hi,
The following example shows that one needs to do some extra esacping
in order to access keys with slash in it via [[ -v ]]. This is not
very convenient. Is there a way to access a key with [[ -v ]] without
the extra escaping?
Note that the behavior of [[ -v ]] and "${}" is different.
$ ./main1.sh
declare -A x=(['\']=A [b]=B)
i='\\'
[[ -v x[$i] ]]; echo "$?"
0
[[ -v x["$i"] ]]; echo "$?"
0
[[ -v x['\\'] ]]; echo "$?"
0
[[ -v x[\\] ]]; echo "$?"
1
[[ -v x['b'] ]]; echo "$?"
0
i='\'
echo "${x[$i]}"
A
echo "${x[\\]}"
A
for i in "address@hidden"
do
echo "$i"
done
\
b
$ cat main1.sh#!/usr/bin/env bash
# vim: set noexpandtab tabstop=2:
set -v
declare -A x=(['\']=A [b]=B)
i='\\'
[[ -v x[$i] ]]; echo "$?"
[[ -v x["$i"] ]]; echo "$?"
[[ -v x['\\'] ]]; echo "$?"
[[ -v x[\\] ]]; echo "$?"
[[ -v x['b'] ]]; echo "$?"
i='\'
echo "${x[$i]}"
echo "${x[\\]}"
for i in "address@hidden"
do
echo "$i"
done
--
Regards,
Peng
- [Help-bash] Is it possible to not require escaping to access hash key in [[ -v ]]?,
Peng Yu <=