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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T16:28:32+00:00 2026-05-15T16:28:32+00:00

INPUT=10 OUTPUT_IN=20 KEYWORD=IN echo $OUTPUT_$KEYWORD It should display 20 Mainly I am looking to

  • 0
INPUT=10     
OUTPUT_IN=20     
KEYWORD="IN"    
echo $OUTPUT_"$KEYWORD"   

It should display 20

Mainly I am looking to generate the variable name OUTPUT_IN

How to resolve this?

  • 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-15T16:28:32+00:00Added an answer on May 15, 2026 at 4:28 pm

    You can use indirection in Bash like this:

    INPUT=10     
    OUTPUT_IN=20     
    KEYWORD="IN"    
    var="OUTPUT_$KEYWORD"
    echo "${!var}"
    

    However, you should probably use an array or some other method to do what you want. From BashFAQ/006:

    Putting variable names or any other bash syntax inside parameters is generally a bad idea. It violates the separation between code and data; and as such brings you on a slippery slope toward bugs, security issues etc. Even when you know you "got it right", because you "know and understand exactly what you’re doing", bugs happen to all of us and it pays to respect separation practices to minimize the extent of damage they can have.

    Aside from that, it also makes your code non-obvious and non-transparent.

    Normally, in bash scripting, you won’t need indirect references at all. Generally, people look at this for a solution when they don’t understand or know about Bash Arrays or haven’t fully considered other Bash features such as functions.

    And you should avoid using eval if at all possible. From BashFAQ/048:

    If the variable contains a shell command, the shell might run that command, whether you wanted it to or not. This can lead to unexpected results, especially when variables can be read from untrusted sources (like users or user-created files).

    Bash 4 has associative arrays which would allow you to do this:

    array[in]=10
    array[out]=20
    index="out"
    echo "${array[$index]}"
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In IE8 this input.attr(name,exam.exam_Normal[' +normal_id_unique + '].boolean_v); Outputs this only in IE8.... <input propdescname=exam.exam_Normal['1'].boolean_v
i want to output some text in an label <input type=text size=20 maxlength=20 name=pizza1
Let suppose we've database table my_code Input I'll create connection to this database table
How to run executable in Xcode with piped input? For example: echo abc |
How i change audio input and output language in my android code? Should i
In SQL Server, is an OUTPUT parameter actually an INPUT/OUTPUT parameter? I'm assuming this
Basically I am trying to understand and learn the 'this' keyword's working principle in
i am using collect keyword to get an input from the user. now inside
I have to devise a function that will take as input a keyword and
I am a beginner in UNIX. I am finding some difficulty in input/output redirection.

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.