I have a bunch of files such as:
jobReports/NARX_20191212_1.out
jobReports/NARX_20191212_10.out
jobReports/NARX_20197695_2.out
jobReports/NARX_20197695_3.out
jobReports/NARX_20261798_1.out
where the first numeral sequence denotes a jobID, and the second numeral sequence denotes the arrayID.
I want to perform a search on all the .out
files in that directory with jobID equal to 20197695
or 20261798
.
In the command line, this works:
grep "Saving results to" jobReports/NARX_{20197695,20261798}*.out | wc -l
, which gives me a count of occurences of that string in the desired files. In my script I have the following:
#!/bin/bash
myJobs = ( 20197695, 20261798 )
IFS=, eval 'myJobs_string="${myJobs[*]}"'
echo $(grep "Saving results to" jobReports/NARX_{$myJobs_string}*.out |wc -l)
when running, I get the error:
grep: jobReports/NARX_{: No such file or directory
grep: 20197695: No such file or directory
grep: }*.out: No such file or directory
So looks like inside the script, the brace expansion is not working as I expected...what can I do to fix this?