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

nmr
  • 605
  • 6
  • 20

1 Answers1

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.

Costi Ciudatu
  • 37,042
  • 7
  • 56
  • 92