LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Software (https://www.linuxquestions.org/questions/linux-software-2/)
-   -   how to evaluate variable values, details inside (https://www.linuxquestions.org/questions/linux-software-2/how-to-evaluate-variable-values-details-inside-4175581901/)

gglq000 06-09-2016 09:45 PM

how to evaluate variable values, details inside
 
I needed to create array of commands and execute it. However due to some of the commands having space, I had to enclose in single quotes. The only issue is within each commands there are variable that should be evaluated to its values during execution which apparently not happening because I enclosed in single-quotes. Any way to evaluate those during loop?

TOOL_COMMANDS=(\
'cd $LINPACK_LOC' \
'nohup tar -xvf $LINPACK_LOC/$LINPACK_NAME' \
'mv $LINPACK_LOC/$LINPACK_INSTALL_DIR_NAME $LINPACK_LOC/linpack' \



for i in "${TOOL_COMMANDS[@]}"
do
echo command: $i
# $i
done

output:
executing commands needed to setup tools:
command: cd $LINPACK_LOC
command: nohup tar -xvf $LINPACK_LOC/$LINPACK_NAME
command: mv $LINPACK_LOC/$LINPACK_INSTALL_DIR_NAME $LINPACK_LOC/linpack
command: cd $PMEMTEST_LOC
command: nohup tar -xvf /$PMEMTEST_LOC/$SYSDIAG_NAME

lazardo 06-10-2016 01:41 AM

[ ? Single quotes prevent variable substitution ]
[ ? Missing closing ')' ]
[ ? CODE tags around code when posting ]

[ bash 4.3 ]
Code:

$ subme=123
$ test=(
  "its a test"
  for
  "${subme} abc ${subme}"
)

$ for i in "${test[@]}"; do echo $i; done
its a test
for
123 abc 123
$

Cheers,

gglq000 06-10-2016 11:55 AM

thanks, so single and double quotes differ in linux shell huh.
in my case, perils of using python where single and double quotes are same.


All times are GMT -5. The time now is 03:01 PM.