1

I have small snippet of code in bash

# below variable coming from a source file
test_name_tgt_tbl='abc_123'

# this variable coming from another source --> source 2
red_test='test_name'

# Based on source2 variable I need to find value in source 1
out_put=`echo ${red_test}_tgt_tbl`

echo "target=`echo $out_put`"

The result I am getting is below

target=test_name_tgt_tbl

The result I want is below

target=abc_123

How can I achieve that

1
  • 2
    foo=`echo $bar` is a really bad way of writing foo=$bar, btw. Commented Feb 24, 2021 at 22:09

1 Answer 1

1

You can achieve that indirection in bash by writing ${!some_var_name}. Here's how I would go about it:

var_name=${red_test}_tgt_tbl
echo ${!var_name}

Prints abc_123.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.