There are four files I am using here for this task: an input file, the file whose values I want to change, and two shell scripts. The first file, models_linearanalysis_Cep.dat is an input file that is organized as so:
1 0.020 0.700 5.4 1500 4000 2 0.020 0.700 5.4 1500 4050 3 0.020 0.700 5.4 1500 4100 4 0.020 0.700 5.4 1500 4150 5 0.020 0.700 5.4 1500 4200 The columns from 1-6 are respectively organized as directory number (d_number), Z, X, mass, L, and Teff. I want to use the 6 values from every row to change the assignments of the variables in this second file inlist_rsp_Cepheid which has the variables:
RSP_mass = 4.165d0 RSP_Teff = 6050 RSP_L = 1438.8d0 RSP_X = 0.73d0 RSP_Z = 0.007d0 log_directory='LOGS_1' photo_directory='photos_1' In this instance, the directory number (i.e. the number attached to LOGS_ and photos_) is 1.
In my first shell script, Inlists_Bash.sh, shown below I attempt to read values from the six columns of the file models_linearanalysis_Cep.dat here, which I intend to read into a second shell script inlist_changer.sh.
while read -ra fields; do for field in "${fields[@]}"; do bash inlist_changer.sh <<<"$field" done ./mk ./rn done < models_linearanalysis_Cep.dat Finally, with the second shell script inlist_changer.sh, I use the inputs to finally change the lines in inlist_rsp_Cepheid such that the variables have the appropriate values.
#!/bin/bash export OMP_NUM_THREADS=12 #used for testing variables #export mass=4.165d0 #export teff=6050 #export l=1438.8d0 #export x=0.73d0 #export z=0.007d0 #export d_number=2 #read in inputs from the Inlists_Bash.sh file read -p d_number z x mass l teff #inlist directory export MESA_INLIST="/home/nick/mesa-r11701/star/test_suite/rsp_Cepheid_grid/inlist_rsp_Cepheid" #change the lines in the MESA_INLIST file sed -i \ -e "s/^\([[:blank:]]*RSP_mass\).*/\1 = $mass/i" \ -e "s/^\([[:blank:]]*RSP_Teff\).*/\1 = $teff/i" \ -e "s/^\([[:blank:]]*RSP_L\).*/\1 = $l/i" \ -e "s/^\([[:blank:]]*RSP_X\).*/\1 = $x/i" \ -e "s/^\([[:blank:]]*RSP_Z\).*/\1 = $z/i" \ -e "s/^\([[:blank:]]*log_directory\).*/\1 = 'LOGS_$d_number'/i" \ -e "s/^\([[:blank:]]*photo_directory\).*/\1 = 'photos_$d_number'/i" \ "$MESA_INLIST" For the first row, I was expecting inlist_rsp_Cepheid to look like this:
RSP_mass = 5.4 RSP_Teff = 4000 RSP_L = 1500 RSP_X = 0.700 RSP_Z = 0.020 log_directory='LOGS_1' photo_directory='photos_1' However, it is clear something is wrong with how I am reading the inputs between these files as I receive this instead:
RSP_mass = RSP_Teff = RSP_L = RSP_X = RSP_Z = 4000 log_directory='LOGS_' photo_directory='photos_' Would someone please explain what I may be missing or doing incorrectly here?