Being someone who is new to bash scripting, I decided to try and unit test my current project from the start. Currently I have a problem with a single line of code. with it I'm trying to search the directory output_json
for the files that match a regex.
before I show any code here is the directory structure that the script runs in:
full path to working directory:
C:\Users\chris\Google Drive\code projects\Replacement Program for Chile Letters\tests\general bash unit tests.
directory tree of current working directory:
├───general bash unit tests <--(working dir)
├───node_fake_returns
└───output_json
├───email_data-1.json
├───email_data-2.json
├───email_data-3.json
├───variable_data-1.json
├───variable_data-2.json
└───variable_data-3.json
the line that I'm trying to use to return an array containing all the filenames of the variable_data
files is as follows:
local contentVars=$(find "./output_json" -regextype posix-extended \
-regex '.*/output_json/variable_data-\d+.json')
Here's is the entire function used to unit test just in case I having something else wrong with the unit test. note the assertion function is from shunit2.
testFileNameCapturing() {
local contentVars=$(find "./output_json" -regextype posix-extended \
-regex '.*/output_json/variable_data-\d+.json')
local emailDataVars=$(find "./output_json" -regextype posix-extended \
-regex 'variable_data-\d+.json')
assertTrue "[ $contentVars == './output_json/variable_data-1.json' ]"
}
I'm sure this is just a small syntax error, but it really has stalled me for a majority of the day. Any help would be great!