I am currently working with a bash script that passes variables to some legacy code using text files.
The script sets the values of the variables some some legacy program (lp) by 1) creating variables with the prefix lp_ and 2) and then saving the values of these parameters as a text file in lp_run_directory. Here's a sample file:
#!/bin/bash
#Set the parameters here
lp_parameter_a=(0.2 0.4 1)
lp_parameter_b="TRUE"
lp_parameter_c=0
#Set the working directory here (put pwd for generality)
lp_run_directory=$(pwd)"/"
#Write parameter values in the directory
echo ${lp_parameter_a[@]} > $lp_run_directory"parameter_a.txt"
echo ${lp_parameter_b[@]} > $lp_run_directory"parameter_b.txt"
echo ${lp_parameter_c[@]} > $lp_run_directory"parameter_c.txt"
#Run program that depends on parameter values here...
lp_run_directory ="/users/ss/"
echo ${lp_parameter_a[@]} > lp_run_directory"parameter_a.txt"
echo ${lp_parameter_b[@]} > lp_run_directory"parameter_b.txt"
This works fine, but involves a lot of hardcoded text. I'm wondering if someone can help me define a function that can automate this in some way.
I'm not sure about what is possible in bash, but an ideal solution would be a function that takes the names of all of the variables in my workspace that begin with lp_ and then saves all of them to lp_run_directory.
lp_parameter_bandlp_parameter_care not arrays; why are you indexing them like they are?