I have an annoying problem, I want a script to search through a makefile (using grep) for a particular annoying line. The problem is best illustrated concretely:
someMakefile (minimal Makefile):
#!/usr/bin/env bash echo bla bla OBJ_DIR='something' EXE_FILE='my_exe' cp $(OBJ_DIR)/$(EXE_FILE) ../bin/. echo 'doing something else now'
testScript.sh (test for the existence of the difficult line):
#!/usr/bin/env bash set -x foundNumLines = $(grep -in 'cp $(OBJ_DIR)/$(EXE_FILE) ../bin/.' someMakefile) echo "foundNumLines = $foundNumLines" set +x
From the commandline (this DOES work):
$ grep -in 'cp $(OBJ_DIR)/$(EXE_FILE) ../bin/.' someMakefile 5:cp $(OBJ_DIR)/$(EXE_FILE) ../bin/.
From the script (this does NOT work and I cannot figure out how to make it work):
$ ./testScript.sh ++ grep -in 'cp $(OBJ_DIR)/$(EXE_FILE) ../bin/.' someMakefile + foundNumLines = 5:cp '$(OBJ_DIR)/$(EXE_FILE)' ../bin/. ./testScript.sh: line 4: foundNumLines: command not found + echo 'foundNumLines = ' foundNumLines = + set +x
When "grep" works from the script, I wanted to use maybe "wc" or similar, to detect the presence of the line and then do something, based on this...
I just cannot make it work, tried many combinations of "'" \' etc - I hope you understand, what I'm trying to achieve, please help with ideas/suggestions, thanks!