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 6883583
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:24:04+00:00 2026-05-27T05:24:04+00:00

I have a TARGET variable that can be set to dev, test or prod.

  • 0

I have a TARGET variable that can be set to dev, test or prod.

I defined the following lists:

dev=(server1 user1 target1)
test=(server2 user2 target2)
prod=(server3 user3 target3)

Depending on the value of TARGET, I’d like to dynamically associate the variable CONFIG to one of the list.

Let’s say TARGET=dev. I then have

eval CONFIG=\$$TARGET # I expect CONFIG to be a list containing (server1 user1 target1)
echo ${CONFIG[*]}     # OK, it gives (server1 user1 target1)
echo ${CONFIG[1]}    # I would expect to have "server1" but it returns "1", seems like CONFIG is not seen as a list

Any idea ?

  • 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-27T05:24:05+00:00Added an answer on May 27, 2026 at 5:24 am

    eval CONFIG=\$$TARGET sets CONFIG to the string $TARGET. When an array is expanded in a string context, the result is the concatenation of the values in the array, with the first character of IFS inserted as a separator. Thus after the assignment the value of CONFIG is the string server1 user1 target1.

    You need to assign to CONFIG as an array. Since you’re working in zsh, you don’t need to use eval to obtain the value of a variable whose name is in a variable. Use the P parameter expansion flag.

    CONFIG=(${(P)TARGET})
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have the Target Framework set to 2.0 on my windows application, yet when
I have set the target of the pic_form to a div (pic_target). The form
I have an ant target that echo's the content of an eclipse .project file,
I have the following target: <target name=promptforchoice> <input addproperty=choice> Copy the file?. [Y, n]
I have the following PHONY target in Makefile install: echo /usr/bin/shelldecrypt must be writable
(The target browser is IE8) I have a div that contains a list of
I have the following in a AfterGet target in TFS. <ItemGroup> <AssemblyInfoFiles Include=$(SolutionRoot)\**\*assemblyinfo.cs />
With event delegation in jQuery 1.6, you can respond to events that have bubbled
I hope someone can help me. I have a website that uses javascript to
I have a function that has the signature of: function(id,target){ //do stuff } The

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.