I have a makefile and try to create some dependencies with a bash-script. So i like to find c- and h-files which include some specific files. I created a find
-grep
-while
-pipe. My problem is, that my variables are not set inside the while-loop. When i got it right this is because of a subshell which will execute for every while-loop. My first attemps to get it done with this site here document didn't work out. So how can i set my variables in this example inside the loop?
found_strings=0
found_fsdata=0
find $1 -type f -iname '*.[ch]' -print0 | while read -d '' file
do
#echo file ist $file
my_result_strings=`head -100 $file | grep 'http-strings.h'`
my_result_fsdata=`head -100 $file | grep 'httpd-fsdata-erw.h'`
if [ -n "$my_result_strings" ]
then
echo $file enthält $my_result_strings
echo "$(basename $file): http-strings.h" >> $1/Makefile.prebuild
echo "" >> $1/Makefile.prebuild
found_strings=1
echo "found_strings1 $found_strings"
fi
if [ -n "$my_result_fsdata" ]
then
echo $file enthält $my_result_fsdata
echo "$(basename $file): http-fsdata.h http-fsdata.c" >> $1/Makefile.prebuild
echo "" >> $1/Makefile.prebuild
found_fsdata=1
fi
done
if [ -n "$found_strings" ]
then
echo "Abhaenigkeit von http-strings.h hinzugefügt"
echo -e "http-strings.h:" >> $1/Makefile.prebuild
echo -e "\t@perl makestrings -d $1/\$(HTTP_STRINGS)">> $1/Makefile.prebuild
echo "" >> $1/Makefile.prebuild
fi
EDIT: this is also not working:
var=0
while read file
do
var=$var+1
done < <(find $1 -type f -iname '*.[ch]')
echo $var
because i got cannot make pipe for process substitution: Function not implemented
line 14: <(find $1 -type f -iname '*.[ch]'): ambiguous redirect
. I start the shell-script within a makefile under windows7. I don't know if importent.