0

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.

Chris
  • 315
  • 1
  • 4
  • 17
  • i tried `var=0 while read file do var=$var+1 done < <(find $1 -type f -iname '*.[ch]') echo $var` but got the message `line 14: <(find $1 -type f -iname '*.[ch]'): ambiguous redirect` I don't know how to post code in a comment. sorry – Chris Nov 17 '17 at 16:05
  • As stated by the error you got: *cannot make pipe for process substitution: Function not implemented*, this is might be a functionality your shell does not support. The example you added in your question works fine. The result will be `0+1+1+1`... though. Arithmetic expansion in bash would look like: `var = $(( var + 1 ))`. – C0DY Nov 17 '17 at 16:18
  • okay. Than i will go with the output to a temporary file an read it after the loop is finished. Thx – Chris Nov 17 '17 at 16:21
  • Your other problem is apparently simply due to being on Windows I guess...? – tripleee Nov 20 '17 at 05:42

0 Answers0