I am trying to get the number of occurrences in a script and when running the command on the command line, it works fine, but not in a script. Both variables are initialized. FILE_PATH is the absolute path of the file and VARIABLE_NAME is something like firstName or lastName.
VARIABLE_NAME="_firstName"
grep -cP "\(this\.|\s\){1}$VARIABLE_NAME" $FILE_PATH
When I take $VARIABLE_NAME out of the script and replace it directly with what I am looking for, it works as expected, so it is something with the replacement.
Any ideas what I can try?