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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:38:13+00:00 2026-05-30T00:38:13+00:00

I have multiple variables in a shell script; i was trying to save some

  • 0

I have multiple variables in a shell script; i was trying to save some code duplication and wanted to do something like following

# variables
FLAG=SIM
SIM_ICR_KEY_VAL="http://www.example.com/simi/icr"
REAL_ICR_KEY_VAL="http://www.example.com/real"

Based on the FLAG value i want to access the correct variable (without using IF’s)
When i try this it echos the variable name & not the value itself.

 echo $(echo ${FLAG}_ICR_KEY_VAL)

On further note; i need to use these substitutions inline in a sed statememt:

sed "s!${ISTR_KEY}=.*!${ISTR_KEY}=${SIM_ISTR_KEY_VAL}!" > tmp.file

… i am not sure its possible or not, please suggest

  • 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-30T00:38:15+00:00Added an answer on May 30, 2026 at 12:38 am

    Reflection can be achieved with the infamous eval:

    eval thisvar=\$${FLAG}_INC_KEY_VAL;
    echo "We are using $thisvar"
    

    Whenever you find yourself dynamically synthesizing a variable name, though, you are probably Doing It Wrong. You should consider alternatives like arrays:

    ICR_KEY_VAL[0]="http://www.example.com/simi/icr"
    ICR_KEY_VAL[1]="http://www.example.com/real"
    
    SIM=0
    
    echo ${ICR_KEY_VAL[$SIM]}
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have text documents like the following which contain single and multiple variables: title::
I have multiple Controller objects that either execute some script and then redirect to
In some code I'm working on I have noticed that several variables are being
I'm trying to make a mixin with multiple variables in LESS, but for some
Does Javascript have a built-in syntax for selecting multiple variables? Say I'd like to
I had a question about Java Class Path variables. If I have multiple jars
I have multiple projects in a couple of different workspaces. However, it seems like
I have multiple classes that all derive from a base class, now some of
I have a regular expression that returns multiple variables within a match. I am
How can I access multiple variables at different positions? How does %s have to

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.