Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8660413
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T16:14:50+00:00 2026-06-12T16:14:50+00:00

I found an implementation of the associative array here and would like to understand

  • 0

I found an implementation of the associative array here and would like to understand what the code actually does. Here are the piece of the code I don’t understand, and would appreciate the explanation.
‘

put() {
    if [ "$#" != 3 ]; then exit 1; fi  
    mapName=$1; key=$2; value=`echo $3 | sed -e "s/ /:SP:/g"`  #dont understand 
    eval map="\"\$$mapName\""  **#dont understand** 
    map="`echo "$map" | sed -e "s/--$key=[^ ]*//g"` --$key=$value"  #dont understand 
    eval $mapName="\"$map\""  #dont understand 
}
get() {
    mapName=$1; key=$2

    map=${!mapName}
    #dont understand 
    value="$(echo $map |sed -e "s/.*--${key}=\([^ ]*\).*/\1/" -e 's/:SP:/ /g' )"  
}

getKeySet() {
    if [ "$#" != 1 ]; 
    then 
        exit 1; 
    fi

    mapName=$1; 

    eval map="\"\$$mapName\""

    keySet=`
           echo $map | 
           sed -e "s/=[^ ]*//g" -e "s/\([ ]*\)--/\1/g"   #dont understand 
          ` 
}

Thanks.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T16:14:52+00:00Added an answer on June 12, 2026 at 4:14 pm

    So first in order of don’t understands:

    1. this simply checks you always have 3 arguments to the function and if different number is provided exits with 1(error)
    2. This escapes the space chars by replacing them with :SP: so Hi how are you becomes Hi:SP:how:SP:are:SP:you
    3. The map is stored in a var with name the first argument provided to put. So this line adds to the var the following text –$key=$value and here key is the second argument and value is the escaped third argument
    4. get simply stores in value the value for the key provided as second argument(first one is the name of the map)

    To understand better try printing the variable you decided to use for your map after each operation. It’s easy you’ll see 😉
    Hope this makes it clear.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In Matters Computational I found this interesting linear search implementation (it's actually my Java
Im looking to make my own implementation of these Identicons or Gravatars found here
I found an implementation of GetHashCode() that looks like this Guid _hashCode = Guid.NewGuid();
How can I multipy two integers using bitwise operators? I found an implementation here
It looks easy, but I found the implementation tricky. I need that for a
Trying to get my mind around google protobuf. I found some implementation of protobuf
I found Swenson's C implementation of Timsort: https://github.com/swenson/sort mentioned in one of the older
I found a goodlooking example about implementation enums in a different way. That is
I found the article regarding what I want to implement at Queue implementation in
I searched for an implementation of std::map runtime ordering and have found this solution:

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.