<?xml version="1.0" encoding="utf-8"?>
<rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:foaf="http://xmlns.com/foaf/0.1/" xmlns:og="http://ogp.me/ns#" xmlns:rdfs="http://www.w3.org/2000/01/rdf-schema#" xmlns:schema="http://schema.org/" xmlns:sioc="http://rdfs.org/sioc/ns#" xmlns:sioct="http://rdfs.org/sioc/types#" xmlns:skos="http://www.w3.org/2004/02/skos/core#" xmlns:xsd="http://www.w3.org/2001/XMLSchema#" version="2.0" xml:base="https://www.linuxjournal.com/tag/bash-arrays">
  <channel>
    <title>Bash Arrays</title>
    <link>https://www.linuxjournal.com/tag/bash-arrays</link>
    <description/>
    <language>en</language>
    
    <item>
  <title>Creating the Concentration Game PAIRS with Bash</title>
  <link>https://www.linuxjournal.com/content/creating-concentration-game-pairs-bash</link>
  <description>  &lt;div data-history-node-id="1340027" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/bigstock-Terminal-startup-icon-direct--90816239_1.png" width="800" height="400" alt="bash" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/dave-taylor" lang="" about="https://www.linuxjournal.com/users/dave-taylor" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Dave Taylor&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;&lt;em&gt;Exploring the nuances of writing a pair-matching memory game and
one-dimensional arrays in Bash.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;
I've always been a fan of Rudyard Kipling. He wrote some great novels and
stories, mostly about British colonial-era India. Politically correct in our
modern times? Not so much, but still, his books are good fun for readers and still
are considered great literature of its time. His works include &lt;em&gt;The Jungle
Book&lt;/em&gt;,
&lt;em&gt;Captains Courageous&lt;/em&gt;, &lt;em&gt;The Just So Stories&lt;/em&gt; and &lt;em&gt;The Man
Who Would Be King&lt;/em&gt;, among
many others.
&lt;/p&gt;

&lt;p&gt;
He also wrote a great spy novel about a young English boy who is raised as an
Indian native and thence recruited by the British government as a spy. The
boy's name is the title of the book: &lt;em&gt;Kim&lt;/em&gt;. In the story, Kim is trained to
have an eidetic memory with a memory game that involves being shown a
tray of stones of various shapes, sizes and colors. Then it's hidden, and
he has to recite as many patterns as he can recall.
&lt;/p&gt;

&lt;p&gt;
For some reason, that scene has always stuck with me, and I've even tried to
teach my children to be situationally aware through similar games like
"Close your eyes. Now, what color was the car that just passed us?"
Since most of us are terrible observers (see, for example, how conflicting
eyewitness accident reports can be), it's undoubtedly good practice for
general observations about life.
&lt;/p&gt;

&lt;p&gt;
Although it's tempting to try to duplicate this memory game as a program,
the reality is that with just a shell script, it would be difficult. Perhaps
you display a random pattern of letters and digits in a grid, then clear the
screen, then ask the user to enter patterns, but that's really much more
of a game for a screen-oriented, graphical application—not shell scripts.
&lt;/p&gt;

&lt;p&gt;
But, there's a simplified version of this that you can play with a deck
of cards: Concentration. You've probably played it yourself at some point
in your life. You place the cards face down in a grid and then flip up two at
a time to try to find pairs. At the beginning, it's just random guessing,
but as the game proceeds, it becomes more about your spatial memory, and by the
end, good players know what just about every unflipped card is at the beginning of
their turn.
&lt;/p&gt;

&lt;h3&gt;
Designing PAIRS&lt;/h3&gt;

&lt;p&gt;
That, of course, you can duplicate as a shell script, and since it is going to
be a shell script, you also can make the number of pairs variable. Let's
call this game PAIRS.
&lt;/p&gt;

&lt;p&gt;
As a minimum, let's go with four pairs, which should make debugging easy.
Since there's no real benefit to duplicating playing card values,
it's just as easy to use letters, which means a max of 26 pairs, or 52
slots. Not every value is going to produce a proper spread or grid, but if
you
aim for 13 per line, players then can play with anywhere from 1–4 lines of
possibilities.
&lt;/p&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/creating-concentration-game-pairs-bash" hreflang="en"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 29 Aug 2018 12:00:00 +0000</pubDate>
    <dc:creator>Dave Taylor</dc:creator>
    <guid isPermaLink="false">1340027 at https://www.linuxjournal.com</guid>
    </item>
<item>
  <title>Bash Associative Arrays</title>
  <link>https://www.linuxjournal.com/content/bash-associative-arrays</link>
  <description>  &lt;div data-history-node-id="1011695" class="layout layout--onecol"&gt;
    &lt;div class="layout__region layout__region--content"&gt;
      
            &lt;div class="field field--name-field-node-image field--type-image field--label-hidden field--item"&gt;  &lt;img src="https://www.linuxjournal.com/sites/default/files/nodeimage/story/techtip_2.jpg" width="285" height="250" alt="""" typeof="foaf:Image" class="img-responsive" /&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-node-author field--type-ds field--label-hidden field--item"&gt;by &lt;a title="View user profile." href="https://www.linuxjournal.com/users/mitch-frazier" lang="" about="https://www.linuxjournal.com/users/mitch-frazier" typeof="schema:Person" property="schema:name" datatype="" xml:lang=""&gt;Mitch Frazier&lt;/a&gt;&lt;/div&gt;
      
            &lt;div class="field field--name-body field--type-text-with-summary field--label-hidden field--item"&gt;&lt;p&gt;The bash man page has long had the following bug listed:
"It's too big and too slow" (at the very bottom of the man page).
If you agree with that, then you probably won't want to read
about the "new" associative arrays that were added in version 4.0 of bash.
On the other hand, if you've ever used any modern Office Suite and seen
code-bloat at its finest and just think the bash folks are exaggerating a bit,
then read on.&lt;/p&gt;
&lt;/div&gt;
      
            &lt;div class="field field--name-node-link field--type-ds field--label-hidden field--item"&gt;  &lt;a href="https://www.linuxjournal.com/content/bash-associative-arrays" hreflang="und"&gt;Go to Full Article&lt;/a&gt;
&lt;/div&gt;
      
    &lt;/div&gt;
  &lt;/div&gt;

</description>
  <pubDate>Wed, 28 Apr 2010 16:09:47 +0000</pubDate>
    <dc:creator>Mitch Frazier</dc:creator>
    <guid isPermaLink="false">1011695 at https://www.linuxjournal.com</guid>
    </item>

  </channel>
</rss>
