[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: test '-v' - associative vs. normal array discrepancy - a bug ?
From: |
Stephane Chazelas |
Subject: |
Re: test '-v' - associative vs. normal array discrepancy - a bug ? |
Date: |
Fri, 21 Nov 2014 11:13:26 +0000 |
User-agent: |
Mutt/1.5.21 (2010-09-15) |
2014-11-21 10:45:53 +0800, konsolebox:
[...]
> blackbox() {
> [[ $1 == [[:alpha:]_]*([[:alnum:]_]) ]] || return 1 ## Or use
> print_error_message_and_exit().
> declare -n arg=$1; printf '%s\n' "$arg" ## Even just using ${!1}
> would work.
> }
[...]
Or use
eval "arg=\${$1}"
Or:
eval "arg=\"\${$1}\"" # for ${array[*]}
which has the benifit to also work with $0, $-, $!, $$,
${array[4]} (but obviously not so well with $1, $?, $#, $arg...)
and as Greg pointed out is not any more dangerous than declare
-n.
> to it is valid since if the user can do "blackbox 'a[b=$(something_evil)]'",
> then why would he not just run something_evil directly anyway. If it's
> anything other than that then it's probably the scripts being called or is
> running the automation that should be questioned.
Greg's point was that "declare -n" is not any less dangerous
than using eval here.
--
Stephane
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, (continued)
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Eduardo A . Bustamante López, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Stephane Chazelas, 2014/11/20
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, konsolebox, 2014/11/20
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, konsolebox, 2014/11/20
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Greg Wooledge, 2014/11/20
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, konsolebox, 2014/11/20
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?,
Stephane Chazelas <=
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, konsolebox, 2014/11/21
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Greg Wooledge, 2014/11/21
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, konsolebox, 2014/11/21
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Chet Ramey, 2014/11/23
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19
- Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Chet Ramey, 2014/11/19
Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Piotr Grzybowski, 2014/11/19
Re: test '-v' - associative vs. normal array discrepancy - a bug ?, Chet Ramey, 2014/11/19