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

  • SEARCH
  • Home
  • 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 1106009
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T01:43:29+00:00 2026-05-17T01:43:29+00:00

I am trying to create nested array’s dynamically from a string that has been

  • 0

I am trying to create nested array’s dynamically from a string that has been parsed (parameter expansion) using a for loop in bash and I am failing:

user@server:/home/user> foo=one,two,three
user@server:/home/user> for i in ${foo//,/" "}; do echo ${i}; done
one
two
three
user@server:/home/user> for i in ${foo//,/" "}; do declare -a ${i}=(var1=foo var2=foo var3=foo); done
-bash: syntax error near unexpected token `('

I can create the nested array manually and it works:

user@server:/home/user> declare -a one=(var1=foo var2=foo var3=foo)
user@server:/home/user> echo ${one[*]}
var1=foo var2=foo var3=foo

Any help would be appreciated!

  • 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-05-17T01:43:30+00:00Added an answer on May 17, 2026 at 1:43 am
    ecik@ecikovo / $ x=one
    ecik@ecikovo / $ echo $x
    one
    ecik@ecikovo / $ declare -a $x=(var1=foo var2=foo)
    bash: błąd składni przy nieoczekiwanym znaczniku `('
    ecik@ecikovo / $ declare -a $x='(var1=foo var2=foo)'
    ecik@ecikovo / $ echo ${one[0]}
    var1=foo
    ecik@ecikovo / $ echo ${one[1]}
    var2=foo
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to create nested routes for a project that has many boards.
I am trying to create a 2d array using nested containers. I want to
I am trying to create nested repeaters dynamically using ITemplate. This repeater is like
Trying to create a nested hash in Perl that is populated with entries from
I am trying to replace an Object inside my nested array (colArray) by using
I'm using the awesome_nested_set plugin in my Rails project. I'm trying to create nested
I'm trying to create a horizontal list from a nested list markup, as an
I'm trying to create a chess game board with 8x8 buttons. I'm using nested
Ok so what I'm trying to do is create an array of pointers that
I'm trying to create a nested comment system using PHP and MySQL. But I'm

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.