0

I have a variable whose contents are lower case. I want to use make that variable's contents upper case and use them as the prefix for a second variable and pass that information to another script as an argument. Currently what's happening is what's getting passed is the name of the second variable instead of it's contents. How to I ensure that this variable is actually evaluated instead of processed as just its name?

PRJ_NAME=project_a
PROJECT_A_SIM_DIR = /ex/path/project_a/sim_dir
PROJECT_B_SIM_DIR = /xe/thap/other_dir_b/sims

UCASE_PRJ_NAME=$(echo $PRJ_NAME | tr '[lower:]' '[:upper:]')

MULTI_PRJ_DIR='$'$(eval "echo ${UCASE_PRJ_NAME}_SIM_DIR")

#Script takes one argument that should be a file path source ex_script.bash $MULTI_PRJ_DIR

 #inside ex_script.bash
 echo $1

 #Desired result: /ex/path/project_a/sim_dir
 #Current result: $MULTI_PRJ_DIR

I also tried

source ex_script.bash ${!MULTI_PRJ_DIR}

That gave a bad substitution error.

The goal overall here would be that if PRJ_NAME was equal to project_a I would pass ex_script /ex/path/project_a/sim_dir and if PRJ_NAME was equal to project_B I would pass ex_script /xe/thap/other_dir_b/sims

Thank you

  • MULTI_PRJ_DIR shouldn't include the $ if you're using ${!MULTI_PRJ_DIR}. It should be: MULTI_PRJ_DIR="${UCASE_PRJ_NAME}_SIM_DIR", or even just MULTI_PRJ_DIR=${PRJ_NAME^^}_SIM_DIR – muru Jul 13 '23 at 02:30
  • @muru Thank you! That was indeed the issue – Greyspectre Jul 13 '23 at 17:00

0 Answers0