[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Syntax Question...

From: Dennis Williamson
Subject: Re: Syntax Question...
Date: Sun, 14 Aug 2011 19:40:45 -0500

On Sun, Aug 14, 2011 at 6:31 PM, Linda Walsh <address@hidden> wrote:
> Re:   BashFAQ/006: http://mywiki.wooledge.org/BashFAQ/006
> Pierre Gaston wrote:
>> Linda:
>>> please show quote the section
>>> that shows using an variable that holds the name of an array to be used
>>> (and assigned to)....  else ...
>> The proof is in the faq, you could have found it if you were not busy
>> trolling the list.
> ====
> Guess this was not possible.
> The FAQ covers indirect,
> it covers arrays,
> but I see no place where it covers the combination.
> If you see such, then quote it.  Don't just wave your arms around
> making unsubstantiated claims or accusations.
> I didn't ask for the impossible -- just a quote.
> Apparently that was too much to ask for, so you call me a troll....ya,
> right.
> Who's the troll?

In short, it says "don't do that." To elaborate, if you need complex
data structures, use a language that supports them. Python for

A selection of the relevant passages:

Obligatory Note

Putting variable names or any other bash syntax inside parameters is
generally a bad idea. It violates the separation between code and
data, and as such puts you on a slippery slope toward bugs, security
issues, etc. Even when you know you "got it right", because you "know
and understand exactly what you're doing", bugs happen to all of us
and it pays to respect separation practices to minimize the extent of
damage they can cause.

Aside from that, it also makes your code non-obvious and non-transparent.

Normally, in bash scripting, you won't need indirect references at
all. Generally, people look at this for a solution when they don't
understand or know about Bash Arrays or haven't fully considered other
Bash features such as functions.

. . .

This is the kind of approach we'd expect in a high-level language,
where we can store hierarchical information in advanced data
structures. The difficulty here is that we really want each element of
the associative array to be a list or another array of command
strings. But the shell simply doesn't permit that kind of data

So, often it pays to step back and think in terms of shells rather
than other programming languages. Aren't we just running a script on a
remote host? Then why don't we just store the configuration sets as
scripts? Then it's simple

. . .

If you need an associative array but your shell doesn't support them,
please consider using AWK instead.

. . .

Bash can almost do it -- some indirect array tricks work, and others
do not, and we do not know whether the syntax involved will remain
stable in future releases. So, consider this a use at your own risk

. . .

The bad news is that if you fail to sanitize the right hand side
correctly, you have a massive security hole. Use eval at your own

Please try to be briefer and more on topic in your posts to this list,
by the way.

Visit serverfault.com to get your system administration questions answered.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]